开发者

How can I center my image in horizontal orientation?

开发者 https://www.devze.com 2023-01-08 22:10 出处:网络
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.

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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消