2011-09-06 15 views
0

我有一个添加到UIView的ImageView。现在我需要zoomIn ZoomOut添加到imageView的图像,它再次添​​加子视图UIView。如何放大UIView里面的ZoomOut

现在可以获得图像的缩放效果。

我今天尝试不走运。

回答

1

您将需要使用滚动视图。滚动型添加到您的笔尖(或做编程然后加载的UIImage,将其添加到的UIImageView,那么添加的UIImageView到滚动视图: //你里面viewDidLoad中

UIImage * image = //set image here 
previewImageView = [[UIImageView alloc] initWithImage:image]; 
scrollView.contentSize = CGSizeMake(320, 480); 
[scrollView addSubview:previewImageView]; 
scrollView.minimumZoomScale = 0.4; 
scrollView.maximumZoomScale = 4.0; 
scrollView.delegate = self; 
[scrollView setZoomScale:scrollView.minimumZoomScale]; 

添加您的姿态方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollview { 
    return self.previewImageView; 
} 



- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center { 
    CGRect zoomRect; 
    zoomRect.size.height = [self.scrollView frame].size.height/scale; 
    zoomRect.size.width = [self.scrollView frame].size.width/scale; 

    zoomRect.origin.x = center.x - (zoomRect.size.width/2.0); 
    zoomRect.origin.y = center.y - (zoomRect.size.height/2.0); 

    return zoomRect; 
} 

- (void)zoomAction:(UIGestureRecognizer *)gestureRecognizer { 

    NSLog(@"Hit the gestureRecognizer"); 
    float newScale = [self.scrollView zoomScale] * 2; 
    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]]; 
    [self.scrollView zoomToRect:zoomRect animated:YES]; 
} 

编辑 - 我有我的高度和宽度在我CGSizeMake

+0

混合@提梧编码器的代码为我工作......如果我需要缩放效果我可以去与UIScrollView和UIWebV IEW。 [这是完美的吗?] – user891268

0

试试这个,

UITouch *first = twoTouches objectAtIndex:0; 
UITouch *second = twoTouches objectAtIndex:1; 
CGPoint firstPoint = first locationInView:self; 
CGPoint secondPoint = second locationInView:self; 
CGFloat initialDistance = distanceBetweenPoints(firstPoint, secondPoint); 

,并把self.multipleTouchEnabled = YES;

1

尝试添加的ImageView在网页观看或在一个滚动视图然后缩放将很容易。