How can I center my image in horizontal orientation?
I have an image view that is inside of a UIScrollView so that I can pinch & zoom. My image looks fine in portrait mode, but when I go to horizontal orientation the image is not centered.
The UIScrollView is 320x460.
Here is my code:
- (void)vi开发者_运维技巧ewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 320, 460);
self.imageView = [[[AsyncImageView alloc]initWithFrame:frame] autorelease];
[self.imageView loadImageFromURL:self.url];
scrollView.contentSize = CGSizeMake(self.imageView.frame.size.width, self.imageView.frame.size.height);
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 0.75;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:self.imageView];
}
And the UIScrollView delegate method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
How can I center my image in horizontal orientation?
Try autoresizing the scroll view:
scrollview.autoresizingMask = ( UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth );
精彩评论