下面是放置圖像的示例,該圖像響應捏合縮放。基本上,您將UIImageView
放在UIScrollView
中並更改一些設置。
UIImageView *myImage;
UIScrollView *myScroll;
-(void)viewDidLoad{
myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,360,450)];
[myImage setImage:[UIImage imageNamed:@"coolpic.png"]];
myImage.contentMode = UIViewContentModeScaleAspectFit;
[myScroll addSubview:myImage];
[myScroll setContentSize:CGSizeMake(myImage.frame.size.width, myImage.frame.size.height)];
[myScroll setMinimumZoomScale:1.0];
[myScroll setMaximumZoomScale:4.0];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return myImage;
}
當然,請正確設置所有代表和IB鉤子。
編輯:我剛剛重讀你的問題。回答您的問題的示例部分是UIImageView的框架規範及其contentMode
設置。
我有很多滾動視圖跳轉的問題,以及如何無法放大特定區域 - 它必須是UIViewContentModeScaleAspectFit !!!! – Rambatino 2014-11-06 20:20:48