使用OS 3.1我在UIScrollView中放置了一个点击检测图像视图(取自Apple的Scroll View套件样本),并且想要在图像视图出现时进行两次缩放。第一个缩放是使整个图像可见,第二个缩放是放大到指定区域。我现在拥有的是:
- (void)viewDidLoad {
// After adding scroll view and image view
imageScrollView.minimumZoomScale = 0.5;
imageScrollView.maximumZoomScale = 2.75;
imageScrollView.zoomScale = 1.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate: self];
[imageScrollView zoomToRect:[imageView frame] animated:YES];
[UIView commitAnimations];
和以下内容检测第一次缩放的结束并触发第二次:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
selectedRect.origin.x = 60.0;
selectedRect.origin.y = 90.0;
selectedRect.size.width = 90.0;
selectedRect.size.height = 90.0;
imageScrollView.minimumZoomScale = 1.0;
imageScrollView.maximumZoomScale = 2.75;
imageScrollView.zoomScale = 2.5;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate: self];
[imageScrollView zoomToRect:selectedRect animated:YES];
[UIView commitAnimations];
这会导致无限循环并且滚动视图在两个放大点之间反复“摆动”。我应该做些什么呢?谢谢。
答案 0 :(得分:1)
当然,您只需将当前的zoomScale检查为scrollViewDidEndZooming中的第一个动作。如果您已放大,请不要进行新的缩放。