0

我已经在我imageview的应用程序中实现了放大scrollview应用程序。我想在视图的右上方设置scrollviewand 。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;
}

请帮我。

4

2 回答 2

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。如果这没有帮助,我将分享我的实现。

于 2012-12-18T06:14:13.373 回答
0

您应该设置zoomScale属性的值scrollview以开始缩放,如下所示。

scrollView.zoomScale=1.0; // this will enable zooming.
于 2012-12-18T05:54:58.803 回答