I am trying to mimic UINavigationController’s pushViewController using UIView animation but I have seem to run into an issue. I cannot animate the self.view.frame.
This is the code I am using but self.view just won’t move!
[self.view addSubview:myViewController.view];
[myViewController.view setFrame:CGRectMake(320, 0, 320, 480)];
[UIView animateWithDuration:0.5
animations:^{
[self.view setFrame:CGRectMake(-320, 0, 320, 480)];
[myViewController.view setFrame:CGRectMake(0, 0, 320, 480)];
}
completion:^(BOOL finished){
[view1.view removeFromSuperview];
}];
Thanks!
Consider where the views are just before the animations start:
self.view.frameis (I assume) 0,0,320,380myViewController.viewis a subview ofself.viewmyViewController.view.frameis 320,0,320,480 inself.view‘s coordinate system, so it’s outside of its superview’s frame (and off the right edge of the screen)Now consider where the views are after the animations finish:
self.view.frameis -320,0,320,480myViewController.viewis still a subview ofself.viewmyViewController.view.frameis 0,0,320,480 inself.view‘s coordinate system, so it’s fully inside its superview’s frame, but its frame in screen coordinates is -320,0,320,480, so it is now entirely off the left edge of the screenYou need to make
myViewController.viewa sibling ofself.view, not a subview. Try this: