开发者

Position of UIScrollView after change in orientation

I have a UIScrollView with an image inside it. This is the code:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    UIScrollView *imScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 96)];
    [imScrollView addSubview:imView];
    [imScrollView setContentSiz开发者_开发问答e:CGSizeMake(530, 96)];
    [[self view] addSubview:imScrollView];
    [imView release];
    [imScrollView release];
}

This is what it looks like in portrait mode:

Position of UIScrollView after change in orientation

I want to know 1. How can I position the image exactly in the middle of the screen (horizontally). 2. How can I make sure this is going to be the same if the orientation switches to landscape. This is what currently the landscape looks like :

Position of UIScrollView after change in orientation

Thanks.


Try setting the autoresizingMask property of your imView just after you create it:

imView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;

The UIView class reference contains more info.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜