当捏缩小超出其最小缩放限制并且即将动画回来时,我试图得到通知UIScrollView
,但我发现它非常困难。有没有办法可以delegate
单独使用方法来做到这一点,或者我是否需要覆盖UIScrollView's
触摸处理?
问问题
6744 次
4 回答
11
使用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");
}
}
}
于 2013-12-16T13:45:49.980 回答
2
您可以使用 UIScrollView 的scrollViewDidZoom
委托方法来检测它即将动画回来的时刻。当视图被捏住时,你会看到scrollView.zoomScale
下面的下拉。scrollView.minimumZoomScale
然后,只要用户松开手指,scrollViewDidZoom
就会再次调用scrollView.zoomScale == scrollView.minimumZoomScale
, 但是scrollView.zooming == NO
。
捕捉这一刻很好,但尝试做任何事情来抢占反弹到最小缩放比例动画对我来说似乎有非常奇怪的副作用。:(
于 2011-03-04T04:17:12.917 回答
2
在 Swift 4.0 中:
func scrollViewDidZoom(_ scrollView: UIScrollView) {
if scrollView.zoomScale == scrollView.minimumZoomScale
{
print("zoomed out")
}
}
这将在用户完成缩放并且 zoomScale 处于其最小可能值时调用,即当滚动视图完全缩小时。
于 2019-01-12T22:48:08.363 回答
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;
}
于 2013-01-12T14:10:06.613 回答