我正在尝试设置嵌套的UIScrollViews。我有两个滚动视图具有相同的内容大小640 * 640设置如下:canvasScrollView(a UIScrollView
)> contentScrollView(a UIScrollView
)>内容(UIView
)。这些都在UIViewController
中。我想要发生的是,当用户在contentScrollView中的内容上缩放 时,canvasScrollView视图以相同的因子和速度缩放 out 。我尝试过设置如下代码:
#import "ViewController.h"
#import "ContentView.h"
@interface ViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *canvasScrollView;
@property (strong, nonatomic) UIView *viewForZoom;
@property (strong, nonatomic) ContentView *content;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
contentScrollView.contentSize=CGSizeMake(640 ,640);
contentScrollView.minimumZoomScale=0.25;
contentScrollView.maximumZoomScale=1;
self.content = [[[NSBundle mainBundle] loadNibNamed:@"floatingView" owner:self options:nil] objectAtIndex:0];
self.viewForZoom=self.content;
[contentScrollView addSubview:self.content];
contentScrollView.delegate=self;
//canvasScrollView was setup in the interface builder, same dimensions as above 320*568
self.canvasScrollView.contentSize=CGSizeMake(640 ,640);
self.canvasScrollView.minimumZoomScale=0.25;
self.canvasScrollView.maximumZoomScale=1;
self.canvasScrollView.userInteractionEnabled=NO;
[self.canvasScrollView addSubview:contentScrollView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.viewForZoom;
}
我的第一步是确保它是缩放的contentScrollView而不是canvasScrollView。使用上面的代码,视图加载正常,但我无法平移或缩放内容。我不确定为什么这不起作用。我已经从用户交互中禁用了canvasScrollView,因为稍后将以编程方式对其进行修改,我还设置了contentScrollView委托。虽然没有工作。真的很感激这一点的帮助!!!
由于
答案 0 :(得分:-1)
您已将contentScrollView
添加到具有userInteractionEnabled=NO
的视图中。不允许用户交互的视图不允许用户交互任何子视图。请尝试将其附加到self.view
。
[self.view addSubview:contentScrollView];