ios - How to track a zooming UIScrollView? -
I have the zooming UIScrollView and a non-zooming overlay view on which I animate the markers to mark these markers some of the UIScrollView Need to track the location of the material (the way the dropped pin needs to track a location on the map as you pan and zoom).
I do this by triggering an update of the overlay view in response to the layout subviews
of UIScrollView. It works, and while the zooming and panning, the overlay is completely tracked.
But when the pinch gesture ends, the UICrol view automatically makes the final animation, and the overlay view is out of sync for the duration of this animation. / P>
I have created a simplified project to isolate the problem, the UIScrollView contains an orange class, and the overlay view displays a 2-pixel red frame around the frame of this orange square. As you can see below, the red layout always goes to the place where after the touch has ended, except for a short period, when it appears on the final state of orange square.
this test The full Xcode project is available here: But all the codes are in two files below:
TrackedScrollView.swift :
Class TrackedScrollView: UIScrollView {@ OverloadsView: UIView? Categories are: UIView Proteus aDecoder required init (cipher: NSCoder) {class = UIView (frame: CGRect (X: 50 Y: 300, width: 300, height: 300)) square.backgroundColor = UIColor.orangeColor ( ) super.init (Coder: aDecoder) self.addSubview (square) self.maximumZoomScale = 1 self.minimumZoomScale = 0.5 self.contentSize = CGSize (width: 500, height: 900) self.delegate = self} override function LayoutSubviews () {super.layoutSubviews () overlay view? .setNeedsLayout ()}} extension TrackedScrollView: UIScrollViewDelegate {func viewForZoomingInScrollView (scrollView: UIScrollView) - & gt; UIView? {Return category}}
OverlaysView.swift :
class OverlaysView: UIView {@IBOutlet bridesmaid trackedScrollView: TrackedScrollView? Profile do: CALayer Proteus aDecoder required init (cipher: NSCoder) {profile = CALayer () outline.borderColor = UIColor.redColor () CGColor outline.borderWidth = 2 super.init. (Coder: aDecoder) self.layer.addSublayer (Profile)} override function layoutSubviews () {super.layoutSubviews () to that trackedScrollView = self.trackedScrollView {CATransaction.begin () CATransaction.setDisableActions (right) to frame = TrackedScrollView.convertRect (trackedScrollView.square.frame, toView: auto) outline. Frame = Sijiartiintegral (Sijiaraksaksset (frame, -3, -3)) Siaararsaanssiakssimmti ()}}}
I tried the thing, it is a CADisplayLink
and presentationLayer
and it has allowed me to animate the overlay, but the coordinates I received from the presentationLayer
is slightly behind the actual UIScrollView, so it's just D also does not seem right I think the system overrun the system correctly My overlay update has to be tie in the UIScrollView animation, but I have not had success in hacking it yet.
How do I always update this code to UIScrollView zooming content?
sends UIScroll view
scrollViewDidZoom:
In the animation block of the representative, if it is "rant" back on the small or zoom zoom, when the pinch ends, update the frame of your overlay to scrollViewDidZoom:
if zoombowsing
This is the truth. If you are using auto layout calls, then layout is encrypted
.
scrollViewDidZoom:
is called only once during zoom bounce animation, but adjusting your frames or layoutIfNeeded
Calling> will ensure these changes are animated with zoom bounce, thus keeping them completely in sync.
Demo:
Comments
Post a Comment