UIScrollView의 축소 원리 해석
6126 단어 【개발 관련】
코드로 축소 가능한 그림 만들기
// ViewController.m
#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property(weak,nonatomic)UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIScrollView *scrollView = [[UIScrollView alloc] init];
// scrollview 375*667(4.7 )
scrollView.frame = self.view.bounds;
[self.view addSubview:scrollView];
scrollView.minimumZoomScale = 0.02;
scrollView.maximumZoomScale = 2;
//
scrollView.delegate = self;
// imageview ,
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ab179aaejw1f44f5h8np9j23402c0kjl"]];
[scrollView addSubview:imageView];
//
self.imageView = imageView;
//
scrollView.contentSize = imageView.image.size;
// ,
scrollView.contentOffset = CGPointMake(0, -64);
// top 64
scrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
}
//
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
@end
:To support zooming, you must set a delegate for your scroll view. The delegate object must conform to the UIScrollViewDelegate protocol. In many cases, the delegate will be the scroll view’s controller class. That delegate class must implement the viewForZoomingInScrollView: method and return the view to zoom. The implementation of the delegate method shown below returns the value of the controller’s imageView property, which is an instance of UIImageView. This specifies that the imageView property will be zoomed in response to zoom gestures, as well as any programmatic zooming.
축소를 지원하기 위해서 UIScroll View Delegate 프로토콜을 준수해야 한다는 뜻입니다.많은 경우, 의뢰는 스크롤 보기 컨트롤러 종류입니다.이 의뢰 클래스는viewForZoomingInScrollView: 방법을 실현하고 축소 보기로 돌아가야 합니다.다음 의뢰 방법의 실현은 이미지 뷰 속성을 되돌려줍니다. 이것은 UIImageView입니다.여기서 imageView 속성이 배율의 영향을 받도록 지정합니다.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
데이터는 여기를 클릭하여 이전 글의 그림을 참고하십시오
확대/축소