[英]How Can I Move An UIImageView Around In A UIScrollView?
In my application, I have a UIImageView inside a UIScrollView. 在我的应用程序中,我在UIScrollView中有一个UIImageView。 I want to zoom and drag the UIImageView.
我想缩放并拖动UIImageView。 I managed to do the zooming but I can't seem to find a way to drag the image inside the UIScrollView using touchesMoved.
我设法做缩放但我似乎找不到使用touchesMoved在UIScrollView中拖动图像的方法。 I have Googled around but it seems that the only method I have found was only possible in iOS 3.0+ but is now obsolete in iOS 4.0+.
我用谷歌搜索过,但似乎我发现的唯一方法只能在iOS 3.0+中使用,但现在在iOS 4.0+中已经过时了。 So how can I drag an image with my finger that is inside a UIScrollView?
那么如何用我的手指在UIScrollView中拖动图像呢?
You shouldn't need to do any touch detection yourself. 您不应该自己进行任何触摸检测。 UIScrollView can take care of everything.
UIScrollView可以处理所有事情。
Here's a example: 这是一个例子:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.delegate = self;
[self.view addSubview:scrollView];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.jpg"]];
scrollView.contentSize = imageView.bounds.size;
[scrollView addSubview:imageView];
float minScale = scrollView.frame.size.width / imageView.frame.size.width;
scrollView.minimumZoomScale = minScale;
scrollView.maximumZoomScale = 2.0;
scrollView.zoomScale = minScale;
}
Don't forget to add this delegate method to enable zooming: 不要忘记添加此委托方法以启用缩放:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.