我在我的应用中实施了imageview
放大scrollview
应用。
我想在视图的右上角设置scrollview
和imageview
。但它并没有放大。当我把它放在view
的中心时,它会缩放。
代码如下:
@interface przoomViewController : UIViewController<UIScrollViewDelegate>
{
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *image;
}
-(void)viewDidLoad
{
[image setUserInteractionEnabled:YES];
[scrollView addSubview:image];
scrollView.scrollEnabled = YES;
scrollView.minimumZoomScale=1.0;
scrollView.maximumZoomScale=4.0;
[scrollView setContentSize:CGSizeMake(320, 180)];
scrollView.delegate=self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return image;
}
请帮帮我。
答案 0 :(得分:0)
您应该为zoomScale
scrollview
属性设置值,以便开始缩放,如下所示。
scrollView.zoomScale=1.0; // this will enable zooming.
答案 1 :(得分:0)
我已在我的应用中实现了图片缩放功能。尝试使用scrollviewDelegate方法
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
// The scroll view has zoomed, so we need to re-center the contents
[self centerScrollViewContents];
}
- (void)centerScrollViewContents
{
CGSize boundsSize = zoomingScrollView.bounds.size;
CGRect contentsFrame = ZImageView.frame;
if (contentsFrame.size.width < boundsSize.width)
{
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
}
else
{
contentsFrame.origin.x = 0.0f;
}
if (contentsFrame.size.height < boundsSize.height)
{
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
}
else
{
contentsFrame.origin.y = 0.0f;
}
ZImageView.frame = contentsFrame;
}
无需在imageView上启用userInterAction。如果这没有帮助,我将分享我的实施。