I am working on an iPad app which has a small popup view in front of the background main view.
The popup view displays one photo and its related notes etc. The main view is a bunch of thumbnails
I want to implement actions, like swipe left/right, to replace the popup view with a new popup view, with animation.
// popView is the existing pop up view to be replaced
MyPopupViewController *newPopView = [[MyPopupViewController alloc] initWithData:...];
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations: ^{
[self.view addSubView: newPopView.view];
[popView removeFromSuperView];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:popView cache:YES];
} completion:^(BOOL finished) { popView = newPopView }
];
[newPopView release];
Well, this doesn't work. I can't remove the old view in animation block otherwise the animation won't fire. I can't remove it in the completion block either, because during the animation, the old image will still be visible under itself.
I've spent quite some time playing with the sequences but just can't get it to work. Please help.
Thanks in advance.
Leo
I finally fixed this by setting the old view hidden in animation block. The animation will reveal the new view during animation.
Here is how I did: it works well in landscape an curls from bottom to top
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionTransitionCurlUp animations:^()
{
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
forView:self.welcomScreen cache:YES];
[self.welcomScreen setHidden:YES];
}completion:^(BOOL finished)
{
[self.welcomScreen removeFromSuperview];
}];
Related
My UIViewController gets the view it is controlling to completely rebuild itself with something like this:
[self.view rebuildYourself:bIsLandscape]; // this line is in the ViewController
The view itself then contains the following method:
-(void)rebuildYourself:(BOOL)isLandscape
{
NSArray *viewsToRemove = [self subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
[self addControls]; // adds lots of views
[self layoutControlsWithOrientation:isLandscape]; // frames the views
}
I would like to animate the entire transition. I have tried this:
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.view rebuildYourself:bIsLandscape];
}
completion:^(BOOL finished){
}];
but the animation ignores the options value of UIViewAnimationOptionTransitionCurlUp and flows in from the top left corner every time.
and I have tried this:
[UIView beginAnimations:#"kkk" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDuration:1.0];
[self.view rebuildYourself:bIsLandscape];
[UIView commitAnimations];
but in this case the transition does curl up nicely but the underlying view is blank until the transition has finished, and then the new view suddenly 'pops' into view, which spoils the effect of the transition.
Can anyone tell me the right/best way to animate a transition where the view rebuilds itself completely?
Thanks
Make two views and put the old view overtop of the new re-built view. Then 'Curl-up' the old view so that the new view is showing and remove the old view from memory.
I have implemented a container view controller (ios5) and now Im trying to implement custom animations/transitions for switching the view controllers.
But I have an issue when implementing any animation that involves a UINavigationController, the result is not as expected. For instance if I perform a flip from left animation when showing the controller with the navigation bar, the position for the navigation bar stays 44pxs below the original position and after the animation is performed the navigation bar will move smoothly to the original position which is really ugly...
This happens with every animation I perform, so I guess it has to be related only with the navigationcontroller.
This is the code I use for the flip transition
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:1.0
options:UIViewAnimationOptionTransitionNone
animations:^{
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:NO];
[UIView commitAnimations];
}
completion:^(BOOL finished) {
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];
I also tried the following
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
}
completion:^(BOOL finished) {
[toViewController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
}];
Set the frame of navigation bar according iphone or ipad's and its orientation like this for portrait in iphone
[self.navigationController.navigationBar setFrame:CGRectMake(0, 20, 320, 44)]; //for iphone simarly for ipad and its orientation
You need to change your navigation bar frame to its actual position from status bar ie plus 20
I have similar problem with NavigationController and Container controller. Actually it was the toolbar at the bottom of window. My solution is to hide the toolbar first, then show toolbar with animation after the main transition completed. It looks like part of the whole animation.
Here is how I hide and show toolbar:
[toNavController setToolbarHidden:YES];
[self transitionFromViewController:fromViewController
toViewController:toNavController
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
}
completion:^(BOOL finished) {
[toNavController didMoveToParentViewController:self];
[fromViewController removeFromParentViewController];
[toNavController setToolbarHidden:NO animated:YES];
}];
In viewDidLoad set frame.origin.y to 1. You still have a jumping but with 1 pixel.
I have 2 views which are the same size, with colourPreview set as a subview of self.view. This is my code for showing the animation:
-(void)startEditingHexLabel {
[UIView animateWithDuration:0.3
animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:hexTextView cache:YES];
[colourPreview removeFromSuperview];
[self.view addSubview:hexTextView];
[self.view sendSubviewToBack:colourPreview];
}
completion:^(BOOL finished){
[hexText becomeFirstResponder];
}];
}
But it just changes to the new view without a transition. Any ideas?
Have you tried using transitionWithView:duration:options:animations:completion: (docs here). Seems this is preferred in iOS 4.0+. There's an example of how to use it in those docs.
If you want to use your current method, I think forView in [UIView setAnimationTransition:forView:cache:] needs to be the superview of the views you want to animate. In your case, this looks to be self.view. Full docs here.
HTH
I am nearly finished with my first IPhone app and everything works fine - except of one very little display bug:
My starscreen is an UIView (Fullscreen) without Navigationbar or Toolbar.
If I tap on a start button, there is an UIViewAnimationTransitionFlipFromRight animation that flips to the main navigation controller:
-(IBAction) switchViewToMainMenu {
[UIView beginAnimations:#"Flip View" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];
[self.navController viewWillAppear:YES];
[self.startScreenViewController viewWillDisappear:YES];
[self.startScreenViewController.view removeFromSuperview];
[self.window addSubview:navController.view];
[self.startScreenViewController viewDidDisappear:YES];
[self.navController viewDidAppear:YES];
[UIView commitAnimations];
self.startScreenViewController=nil;
[startScreenViewController release];
}
This works fine except of one little problem:
When the navigation controller view appears (flips in), the Navigationbar on top is some pixels too high (the is a white bar where the Navigationbar should be). When the animation finished, the Navigationbar drops down to the right position. This doesn't look very beautiful...
Any ideas how to fix that problem ?
We found a solution using the setAnimationDelay giving some time the tabbar to load and placed in view.
Thought you have to alter the code a little in order to use the setAnimationDelay.
You have to use the setyanimationdelay just before the setanimationtransition and the setanimationtransition just before the commitAnimations. So the code above should end to:
[UIView setAnimationDelay:2]; // 2 seconds delay seems to be working for us
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];
[UIView commitAnimations];
I am trying to dismiss a modalviewcontroller with a page curl. The curl works okay but I cannot seem to get the tableview under the modalviewcontroller to show up. The image of the modalviewcontroller is still under the curled away page. If I dismiss the modalviewcontoller before the animation finishes the animation doesn't show up. Here is my code:
//hide splash screen
- (void)hideSplash{
[UIView beginAnimations:nil context:nil];
//change to set the time
[UIView setAnimationDuration:2];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:modelView cache:NO];
// do your view swapping here
//[[self modalViewController] dismissModalViewControllerAnimated:NO];
[UIView commitAnimations];
//[self.view sendSubviewToBack:self.view];
}
Hope someone can help! Cheers Nick
In iOS4:
To present, it's something like:
[containerView addSubview:modelView];
[UIView transitionWithView:containerView
duration:.75
UIViewAnimationOptionTransitionCurlUp
animations:^{}
completion:^(BOOL finished) {
NSLog(#"finished %d", finished);
}];
To dismiss, use UIViewAnimationOptionTransitionCurlDown.
Your setAnimationTransition: shouldn't be forView:modelView; it should be for the parentView.
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:containerView cache:NO];
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html
If you want to change the appearance
of a view during a transition—for
example, flip from one view to
another—then use a container view, an
instance of UIView, as follows:
Begin an animation block.
Set the
transition on the container view.
Remove the subview from the container
view.
Add the new subview to the
container view.
Commit the animation
block.
Use of this method is
discouraged in iOS 4.0 and later. You
should use the block-based animation
methods instead.