[英]I have an UIImageView in an UIScrollView. How do I center at x,y of the image programmatically?
[英]How do I vertically center a UIImageView in a UIScrollView programmatically?
我有一個視圖控制器,將UIImageView
放在UIView
包裝器中,然后將其放入UIScrollView
。 我需要將圖像完全縮小並垂直居中。
視圖控制器已實例化,並在UIPopoverController
。
這是我為視圖控制器編寫的代碼:
- (void) loadView
{
UIImageView *imageView = [[UIImageView alloc]initWithImage:self.image];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:imageView.frame];
scrollView.delegate = self;
scrollView.bounces = NO;
self.containerView = [[UIView alloc] initWithFrame:imageView.frame];
[self.containerView addSubview:imageView];
[scrollView addSubview:self.containerView];
scrollView.minimumZoomScale = .4;
scrollView.maximumZoomScale = 5.0;
[scrollView setZoomScale:.4];
self.view = scrollView;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.containerView;
}
我已經嘗試了很多方法來使其居中,但是它始終出現在滾動視圖的頂部。
對UIScrollView使用ContentSize和ContentOffSet
使用自動布局並在滾動視圖中居中放置容器視圖。.如果您需要自動布局幫助,請使用https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html此鏈接。 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.