I wish to obtain one thing like ChatGPT message bubble, examples are in attachment. In case you attempt to lengthy press in ChatGPT app on a message, view of a cell turns into “centered” and scaled based mostly on pressed cell view top. You’ll be able to see in attachments that centered view width is calculated by views top and that complete view is proven, regardless of of its top.
So my query is tips on how to create view like that, what to make use of? I approached this with two options. First one is to create a screenshot of a view, however then its a picture and generally decision just isn’t good.
Second resolution was to simply seize view from a gesture, and add it as subview, however then it can’t be scaled, or perhaps I could not obtain scaling. If message its too lengthy, my content material will get minimize when it can’t longer slot in display screen viewport.
Right here is code what I attempted to date:
@objc func handleLongPress(_ gesture: UILongPressGestureRecognizer) {
guard let tappedView = gesture.view else { return }
tappedView.layer.cornerRadius = 8
if gesture.state == .started {
let blurEffect = UIBlurEffect(type: UIBlurEffect.Model.gentle)
let blurEffectView = UIVisualEffectView(impact: blurEffect)
blurEffectView.body = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)
view.addSubview(tappedView)
view.bringSubviewToFront(tappedView)
let windowsHeight = UIScreen.principal.bounds.top
if tappedView.body.top > windowsHeight {
tappedView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
UIView.animate(withDuration: 0.5, delay: 0, choices: .curveEaseIn, animations: {
tappedView.snp.remakeConstraints { make in
make.high.backside.equalToSuperview().inset(50)
make.main.trailing.equalToSuperview().inset(70)
}
}, completion: nil)
} else {
let cellFrameInViewport = contentView.tableView.convert(tappedView.body, to: UIApplication.shared.keyWindow)
print("cellFrameInViewport", cellFrameInViewport)
tappedView.body = cellFrameInViewport.inset(by: UIEdgeInsets(high: 0, left: 20, backside: 0, proper: 20))
}
} else if gesture.state == .ended {
print("ended")
} else if gesture.state == .cancelled {
print("cancelled")
}
}
The rationale why I used to be checking this line:
“if tappedView.body.top > windowsHeight”
It’s as a result of when view is smaller, shall we say 100 top, I need it to be precisely the place it was place within the first place, since it may well match display screen, it would not want any scaling
Thanks upfront!