我无法放大UIScrollView
工作。所以问题是平移工作正常。但是,捏合和缩放不起作用。我假设的原因是我没有代表。
我的方法:
我尝试使用代表,我想出的唯一解决方案是
scrollView.delegate=self
我知道我需要在 中包含一些东西
ViewController.h
,但我不知道如何放置@property UIScrollView *scrollView;
然后将其连接到缩放功能。
我相信我走在正确的轨道上,但高度赞赏有关在哪里连接的建议。
视图控制器.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
视图控制器.m
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:
CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.delegate = self;
CGSize containerSize = CGSizeMake(1280, 1280);
UIView *containerView = [[UIView alloc] initWithFrame:(CGRect) {.origin=CGPointMake(0.0f, 0.0f), .size=containerSize}];
containerView.backgroundColor = [UIColor grayColor ];
[scrollView addSubview:containerView];
// Set up our custom view hierarchy
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 640.0f, 80.0f)];
redView.backgroundColor = [UIColor redColor];
[containerView addSubview:redView];
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 560.0f, 640.0f, 80.0f)];
blueView.backgroundColor = [UIColor blueColor];
[containerView addSubview:blueView];
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(160.0f, 160.0f, 320.0f, 320.0f)];
greenView.backgroundColor = [UIColor greenColor];
[containerView addSubview:greenView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"slow.png"]];
imageView.center = CGPointMake(320.0f, 320.0f);
[containerView addSubview:imageView];
scrollView.panGestureRecognizer.minimumNumberOfTouches=2;
CGSize containerSize2 = CGSizeMake(640, 640);
scrollView.contentSize=containerSize2;
CGRect viewRect = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
[self.view addSubview:scrollView];
}
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// Return the view that we want to zoom
return self.containerView; //This gives error.
}