开发者

Rotating iPhone and keeping image's proportions

I have an UIScrollView, that contains UIImageViews. All images keep their image ratio - I mean that e.g. portrait image is high and narrow, while landscape image is short and wide. I have about 4 images at same time on screen (2 vertically, 2 horizontally), then I can scroll down.

My problem is rotating the device. I use

[self.imageScrollView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];// (etc)

And same method for imageView. But images don't keep their proportions. If I set: UIViewAutoresizingFlexibleWidth -开发者_运维技巧 image is wide but heigh is too small UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight - image is stretched horizontally, while vertically it's way to small.

I need to rotate the device (portrait->landscape), make these 2 images (that I have next to each other) to fill gap and keep these images proportions.


Try this function..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait) { //Device is portait 
            //Resize the images to fit this orientation
                         image1.frame = CGRectMake(x,x,x,x);
        }
        else {
            //Device is landscape..
        }   
    return YES;
}


imageView.contentMode = UIViewContentModeScaleAspectFill;

This solved my problem ^^

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜