缩放子控件
#import "ViewController.h"
@interfaceViewController ()<UIScrollViewDelegate>
@property (strong, nonatomic) UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad { [superviewDidLoad];
UIScrollView *scrolView = [[UIScrollViewalloc]initWithFrame:self.view.bounds];
// 要实现缩放,就必须告诉scrollView的代理我要缩放哪个子控件(只能缩放内部的子控件)
scrolView.delegate = self;
scrolView.minimumZoomScale = 0.5; scrolView.maximumZoomScale = 2;
// 内部自动调用 // [self viewForZoomingInScrollView:scrolView];
// imageView的size默认就是图片的大小 UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"0.jpeg"]]; self.imageView = imageView;
scrolView.contentSize = CGSizeMake(imageView.bounds.size.width,imageView.bounds.size.height);
[scrolView addSubview:imageView]; [self.viewaddSubview:scrolView]; }
-(UIImageView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { returnself.imageView; }
// 正在缩放时调用,一直调用(无数次) -(void)scrollViewDidZoom:(UIScrollView *)scrollView { // NSLog(@"scrollViewDidZoom------"); }
// 缩放完毕调一次 -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale { // NSLog(@"scrollViewDidEndZooming-%@--%f---",view,scale); }
// 每次拖动调用一次 -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { NSLog(@"scrollViewWillBeginDragging----"); }
@end
|