UIScrollView 与 UIImageView。图像未向上滚动
Posted
技术标签:
【中文标题】UIScrollView 与 UIImageView。图像未向上滚动【英文标题】:UIScrollView with UIImageView. Image is not scrolled up 【发布时间】:2014-07-10 19:13:55 【问题描述】:这是UIScrollView
、UIImageView
的代码。
When the next image is chosen the resetStatusImage
is called. statusMessageImageView
作为放大 UIScrollView 委托的视图返回。
当使用最小缩放时,图像无法向上滚动,但仍有图像部分需要滚动。至于底部、左侧和右侧,它们是完全可见的,不能分别向下、向左和向右滚动。为什么最小缩放时图像不能向上滚动?
- (void)viewDidLoad
CGRect r = CGRectMake(0, 0, self.statusMessageTextView.bounds.size.width, 455);
statusMessageImageView = [[UIImageView alloc] initWithFrame:r];
statusMessageImageView.contentMode = UIViewContentModeCenter;
// Set up the scroll view for the image zooming in/out and scrolling.
imgScrollView = [[UIScrollView alloc] initWithFrame:statusMessageImageView.bounds];
[imgScrollView setScrollEnabled:YES];
[imgScrollView setClipsToBounds:YES];
[self.view addSubview:imgScrollView];
[imgScrollView setBackgroundColor:[UIColor yellowColor]];
[imgScrollView setContentSize:statusMessageImageView.frame.size]; // this is your image view size
imgScrollView.delegate = self;
UITapGestureRecognizer *doubleTapRecognizer =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewDoubleTapped:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
[imgScrollView addGestureRecognizer:doubleTapRecognizer];
[imgScrollView addSubview:statusMessageImageView];
[imgScrollView addSubview:self.statusMessageTextView];
- (void)resetStatusImage
imgScrollView.zoomScale = 1.0;
UIImage *statusImage = self.statusImageManager.currentStatusImage;
NSLog(@"Image size %f %f", statusImage.size.width, statusImage.size.height);
// Set the image view fram size equal to the image size.
statusMessageImageView.frame = (CGRect).origin=CGPointMake(0.0f, 0.0f), .size=statusImage.size;
[statusMessageImageView setImage:statusImage];
// Set the scroll view content size and zoom scale.
imgScrollView.contentSize = statusImage.size;
CGFloat scaleWidth = imgScrollView.frame.size.width / imgScrollView.contentSize.width;
CGFloat scaleHeight = imgScrollView.frame.size.height / imgScrollView.contentSize.height;
CGFloat maxScale = MAX(scaleWidth, scaleHeight);
imgScrollView.minimumZoomScale = maxScale;
imgScrollView.maximumZoomScale = 1.0f;
imgScrollView.zoomScale = maxScale;
// Save current scroll view content data
// to detect that the user changed the visible area.
contentOffsetX = imgScrollView.contentOffset.x;
contentOffsetY = imgScrollView.contentOffset.y;
zoomScale = imgScrollView.zoomScale;
【问题讨论】:
【参考方案1】:-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll
return imageView;
这会对你有所帮助。
【讨论】:
但这对他有什么帮助?你能补充更多信息吗?【参考方案2】:statusMessageTextView
高度值是错误的。禁用自动缩放也会影响statusMessageTextView
在缩放时的位置,移动图像:文本视图也会移动。
【讨论】:
以上是关于UIScrollView 与 UIImageView。图像未向上滚动的主要内容,如果未能解决你的问题,请参考以下文章
UIScrollView SetContentSize 与自动布局
如何使 UIButton 与 UIScrollView 一起移动
更改 UIImageView 大小以匹配图像与 AutoLayout