开发者

Change background image on ipad after rotation

I show bg of my app using UIImageView. To support correct interface rotation i write layoutSubviews method. In this metod .frame property changes correctly, but when i try chang开发者_运维技巧e image of UIImageView just like this:

view = [self viewWithTag:1002];    
 ((UIImageView *)view).image = [UIImage imageNamed:@"portrait.png"];

nothing changed. Did I do something wrong or is it impossible to change image of UIImageView in layoutSubviews method?


try this

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

    // change background here

    }


You manage the rotation of your views by using a UIViewController (be sure to check out the docs here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html). If you implemented a UIViewController for your UIImageView you could set the image in the viewDidLoad: method.

You shouldn't override the layoutSubviews: method to perform this action. layoutSubviews:is to do what it says in the name - it should perform the positioning and sizing of any subiews that this view currently has. You shouldn't need to override this method unless you wanted to do some special custom laying out of the subviews and is called in the run loop when the UIView is set to "requires resizing".

I strongly suggest you set your image from from some other location in the code. If you want the image to change when the view is rotated, you could set the image in the - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation method of a UIViewController subclass.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜