Ios UIScrollView在压入过程中自动向下滚动?
我已经在uiscrollview中添加了一个图像视图。当我挤压滚动视图时,我可以放大,但滚动视图会自动向下滚动一点。所以我无法缩放uiimageview的底部Ios UIScrollView在压入过程中自动向下滚动?,ios,objective-c,iphone,uiscrollview,Ios,Objective C,Iphone,Uiscrollview,我已经在uiscrollview中添加了一个图像视图。当我挤压滚动视图时,我可以放大,但滚动视图会自动向下滚动一点。所以我无法缩放uiimageview的底部 UIScrollView *scroll = [[UIScrollView alloc]init]; scroll.minimumZoomScale = 1.0f; scroll.maximumZoomScale = 16.0f; scroll.delegate = self; [scroll setC
UIScrollView *scroll = [[UIScrollView alloc]init];
scroll.minimumZoomScale = 1.0f;
scroll.maximumZoomScale = 16.0f;
scroll.delegate = self;
[scroll setContentSize:CGSizeMake(scroll.frame.size.width, scroll.frame.size.height+2200)];
scroll.frame = self.view.frame;
[scroll setBackgroundColor:[UIColor brownColor]];
[self.view addSubview:scroll];
UIImageView *img = [[UIImageView alloc]init];
[img setBackgroundColor:[UIColor yellowColor]];
[img setImage:[UIImage imageNamed:@"add_button.jpg"]];
[img setFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
[img setContentMode:UIViewContentModeScaleAspectFit];
[scroll addSubview:img];
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [[scrollView subviews] firstObject];
}
我假设您正在使用UIPinchGestureRecognizer来处理夹点事件 您要做的是在方法的开头和结尾添加这些“if”语句:
- (void)handlePinch:(UIPinchGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
self.scrollView.enabled = NO;
// pinch handling here
if ((sender.state == UIGestureRecognizerStateEnded) || (sender.state == UIGestureRecognizerStateCancelled))
self.scrollView.enabled = YES;
}
希望这有帮助。这是我的代码,可能会有帮助
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = self.showImgView;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
pinchGestureRecognizer.scale = 1;
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) {
CGRect newFrame = self.showImgView.frame;
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
}];
}
}
我使用的是UIScrollView,它有默认的捏手势动作。-(UIView*)视图用于缩放scrollView:(UIScrollView*)scrollView{return[[scrollView子视图]firstObject];}根据您在OP中所描述的,我认为您希望将UIPinchGestureRecognitor应用于UIImageView,不是UIScrollView。@Tim Kokesh UIScrollView默认使用UIPinchGestureRecognizer,所以我更喜欢使用它。以及我如何裁剪出现在裁剪矩形中的主图像。