当UIScrollView
捏缩小超过其最小缩放限制并且即将动画回来时,我正试图收到通知,但我发现它非常困难。有没有办法可以单独使用delegate
方法执行此操作,还是需要覆盖UIScrollView's
触摸处理?
答案 0 :(得分:9)
使用scrollViewDidZoom:
并检查是否scrollView.zoomBouncing == YES
。然后使用zoomScale
确定视图弹跳的方向。
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
if (scrollView.zoomBouncing) {
if (scrollView.zoomScale == scrollView.maximumZoomScale) {
NSLog(@"Bouncing back from maximum zoom");
}
else
if (scrollView.zoomScale == scrollView.minimumZoomScale) {
NSLog(@"Bouncing back from minimum zoom");
}
}
}
答案 1 :(得分:2)
您可以使用UIScrollView的scrollViewDidZoom
委托方法来检测它即将动画回来的时刻。在视图被挤压时,您会看到scrollView.zoomScale
下方scrollView.minimumZoomScale
。然后,只要用户松开手指,scrollViewDidZoom
将再次使用scrollView.zoomScale == scrollView.minimumZoomScale
,scrollView.zooming == NO
来调用{。}}。
捕捉这个时刻很好,但是尝试做任何事情来抢占反弹至最小的ZoomScale动画似乎对我来说真的有些奇怪的副作用。 :(
答案 2 :(得分:1)
在Swift 4.0中:
func scrollViewDidZoom(_ scrollView: UIScrollView) {
if scrollView.zoomScale == scrollView.minimumZoomScale
{
print("zoomed out")
}
}
当用户完成缩放并且zoomScale处于最小可能值时,即完全缩小滚动视图时,将精确地调用此方法。
答案 3 :(得分:0)
我是用UIPinchGestureRecognizer
完成的。
-(void)viewDidLoad{
UIPinchGestureRecognizer *gestureRecognizer =
[[[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(pinched:)]
autorelease];
gestureRecognizer.delegate=self;
[self.scrollView addGestureRecognizer:gestureRecognizer];
//your code
}
-(void)pinched:(UIPinchGestureRecognizer*)gestureRecognizer{
if(gestureRecognizer.state==UIGestureRecognizerStateEnded){
//pinch ended
NSLog(@"scale: %f",scrollView.zoomScale);
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:
(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}