phu*_*phu 32 zoom uiscrollview ios autolayout
我想实现UIScrollView的新途径,利用自动布局.我已经设置了从内部视图到滚动视图的约束,以便它可以contentSize自动计算它自己,并且就像魅力一样 - 除了当我尝试放大或缩小时所有的地狱都松散了.我甚至无法正确描述发生的事情,除了说内部视图"搞砸了".
你可以在这里看到这种行为的一个例子(不是我的项目;你必须设置滚动视图maximumZoomScale并-viewForZoomingInScrollView:在缩放工作之前实现).
有没有其他人遇到这种行为?目前是否有任何方法可以放大UIScrollView使用自动布局而无需自己重新实现缩放行为?
如果没有在故事板中添加 imageView,我发现以下效果完美:
-(UIImageView *)imageView
{
if (!_imageView) _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
return _imageView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.scrollView addSubview:self.imageView];
// Set the min and max:
self.scrollView.minimumZoomScale = 0.2;
self.scrollView.maximumZoomScale = 5.0;
self.scrollView.delegate = self;
// Set the content:
self.scrollView.zoomScale = 1.0; // reset zoomScale for new image
self.scrollView.contentSize = CGSizeMake(image.size.width/2, image.size.height/2);
self.imageView.frame = CGRectMake(0, 0, image.size.width/2, image.size.height/2);
self.imageView.image = image;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10208 次 |
| 最近记录: |