views:

462

answers:

2

So, in Interface Builder I have a view within the superview that contains two Image View objects. I'd like to move that view off the screen when the app launches so it can be animated to move into place. The view is described as pictureFrame in the .h file for the interface, and I have the view mapped to the outlet pictureFrame. Here is my current viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    CGRect theFrame = [self.pictureFrame frame];
    theFrame.origin.y = -290;
}

But, it doesn't seem to be working. How do I fix this?

+3  A: 

You forget to set your view's frame:

CGRect theFrame = [self.pictureFrame frame];
    theFrame.origin.y = -290;

add this and you're good:

self.pictureFrame.frame = theFrame;

ahmet emrah
A: 

I tend to do these sorts of things as one liners. I find it easier to remember what is going on when I go back and read it later.

I also prefer to #define my view offsets to keep magic numbers out of my code.

#define kPictureFrameHorizontalOffset -290


- (void)viewDidLoad {
    [super viewDidLoad];
    self.pictureFrame.frame = CGRectMake(self.pictureFrame.frame.origin.x + 0,
                                         self.pictureFrame.frame.origin.y + kPictureFrameHorizontalOffset,
                                         self.pictureFrame.frame.size.width + 0,
                                         self.pictureFrame.frame.size.height + 0);
}

Granted it is a bit more verbose, but it works well for me.

Brad Smith