In the app I’m making, I’m trying to make a button start offscreen and move onscreen. I’m not sure how to start with the button offscreen, but I know that once I figure that out, I can do something like the code below:
[UIView beginAnimation:@"animate" context: nil];
[UIView setAnimationDuration:3];
self.myButton.frame = CGRectMake (20, 100, 40, 80);
//Other animations
[UIView commitAnimations];
Additionally, in the line [UIView beginAnimation:@"animate" context:nil];, is the context parameter asking for a CGContextRef?
I assume that you are asking how to get the button to animate from offscreen to onscreen, to do this just set the buttons origin position to coordinates that are located offscreen.
Once you have done this you can just use the code you posted to animate onto the screen. Keep in mind that the button will move from the first position to the second, meaning that if you used the coordinates i used the button would move onto the screen from the left side without the y position changing. Keep in mind that the further offscreen you put the button the faster it will have to move to get onto the screen in the time allotted in the setAnimationDuration.
So to animate onto screen from the left
Also, if the button was previously on the screen it will seem to teleport off the screen and then slide back on when that code is used.
Oh, and to answer your question about the context, no it doesn’t have to be a CGContextRef, it can be any data type (as long as its an object and not a primitive). Its basically the data that gets passed to the delegate when the animation occurs.