我想知道如何使用手势调整ScrollView中的子视图,特别是Pinch Gestures。我不想缩放(我的意思是,我不需要放大/缩小)其内容,但我需要调整视图的框架大小。任何人都可以帮助我吗?
答案 0 :(得分:0)
将捏合手势识别器添加到mainView:
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
pinchGesture.delegate = self;
[mainView addGestureRecognizer:pinchGesture];
[pinchGesture release];
然后对夹点作出反应:
- (IBAction)handlePinchGesture:(UIPinchGestureRecognizer *)sender {
switch (sender.state) {
case UIGestureRecognizerStateBegan:
if([sender scale] < 1){
NSArray *subViews = [mainView subviews];
for( UIView *view in subViews){
//Adjust the size of your subview however you like
CGRect newFrame = CGRectMake(x,x,x,x);
view.frame = newFrame;
}
}else if([sender scale] > 1){
//resize frame (zoom in)
}
break;
default:
break;
}
}
如果您的mainView的选项@property(nonatomic) BOOL autoresizesSubviews
设置为YES
,您只需调整mainView框架的大小,否则您必须浏览所有mainView子视图并相应地调整它们的大小