IPhone dev - set view position in viewDidLoad

So, in Interface Builder, I have a view inside the supervisor that contains two Image View objects. I would like to move this view from the screen when the application starts up, so that it can be animated to move into place. The view is described as a pictureFrame in the .h file for the interface, and I have a view mapped to the output image. Here is my current viewDidLoad:

- (void)viewDidLoad { [super viewDidLoad]; CGRect theFrame = [self.pictureFrame frame]; theFrame.origin.y = -290; } 

But it does not seem to work. How to fix it?

+4
source share
2 answers

You will forget to set your perspective:

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

add this and you are good:

self.pictureFrame.frame = theFrame;

+16
source

I usually do things like one liner. It’s easier for me to remember what happens when I come back and read it later.

I also #define prefer my view offsets to save magic numbers from 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); } 

Provided this is a little more verbose, but it works well for me.

+1
source

Source: https://habr.com/ru/post/1302794/


All Articles