我有一個添加到UIView的ImageView。現在我需要zoomIn ZoomOut添加到imageView的圖像,它再次添加子視圖UIView。如何放大UIView裏面的ZoomOut
現在可以獲得圖像的縮放效果。
我今天嘗試不走運。
我有一個添加到UIView的ImageView。現在我需要zoomIn ZoomOut添加到imageView的圖像,它再次添加子視圖UIView。如何放大UIView裏面的ZoomOut
現在可以獲得圖像的縮放效果。
我今天嘗試不走運。
您將需要使用滾動視圖。滾動型添加到您的筆尖(或做編程然後加載的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
試試這個,
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;
嘗試添加的ImageView在網頁觀看或在一個滾動視圖然後縮放將很容易。
混合@提梧編碼器的代碼爲我工作......如果我需要縮放效果我可以去與UIScrollView和UIWebV IEW。 [這是完美的嗎?] – user891268