I have an app where i add ViewB as a subview to ViewA... But the background of ViewB is clearColor, which means that I can see ViewA through ViewB! If I set viewA to be hidden, ViewB goes away too!
I am making a "flip-transition" between the views, so I can't just remove ViewA and then add ViewB :-/
-Anybody got an idea about what I can do?
Here's my code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:mainTableView
cache:YES];
[mainTableView addSubview:subTableView];
[UIView commitAnimations];
"I am making a "flip-transition" between the views, so I can't just remove ViewA and then add ViewB :-/ " - actually yes, you can. As a first step, you should add ViewA to the parent view. Later on, when you want to do the flip, you remove ViewA, and add ViewB to the parent view, and you do the flip transition on the parent view.
Hope this helps.
I would recommend that you don't add the back view as a sub ViewB as a subview of ViewA. The best solution would be keeping them separate... The method previously mentioned (transitionFromView:toView:duration:options:completion:) is the correct method to use... just make sure you do not have one as a subview of the other... instead, if ViewA is going to be the "back view" then just do this...
[UIView transitionFromView:viewB toView:viewA options:UIViewAnimationOptionTransitionFlipFromRight completion:NULL];
UIViewAnimationOptionFlipFromRight is just one option... read docs for more options....
Check out the help for setAnimationTransition:forView:cache: - it sounds like you want to change the appearance of a view during a transition, flipping from one view to another, both views visible during the animation? In order to do this the docs suggest using a container view. The docs also suggest in iOS 4.0 and later that you use block-based animation.
Try using transitionFromView:toView:duration:options:completion:
Related
This is how I switch from one UIView to another UIView: self.view = MyView;
How would I fade out a view to my MySecondView?
You can use UIView's build in transition code to cross dissolve between them.
[UIView transitionFromView:self.view toView:MySecondView duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
// What to do when its finished.
}];
You can also use the regular animation options with something like this. I haven't tested this code as I'm not in front of Xcode but I use it all the time for labels and things without default animations.
[UIView animateWithDuration:0.25 animations:^{
[self.view setAlpha:0.0];
self.view = mySecondView;
[self.view setAlpha:1.0];
}];
Please note that it's not a good idea to do things like self.view = MyView to change screens. By the time you get to a few screens, your viewController will be filled with spaghetti code. You should consider presenting new view controllers that manage their views. One way you can do fade is as follows:
Fade the current view to black (with animation)
In the view controller that you are going to push use viewWillAppear to fade the view to black as well
Push/Present the view controller without animations.
Now use the viewDidAppear method of the newly presented view controller to fade in the view (with animation).
I was searching information to show a uiwebview using a flip horizontal effect like modal transition one in viewDidLoad event, but I wasn't successful, even in apple documents. Can anybody help me with that?
Many thanks
the transition to animate webView with the view add your webView like this.
[UIView transitionWithView:poster.view duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self.view addSubview:yourWebView];
}
completion:NULL];
The animation you want to add can be done on the UIView. So you should addSubView the UIWebview to the UIView and then do the animation on the UIView.
I have a superview and I've added a subview on superview and added a UIbutton on the subview.My requirement is when I click on UIbutton the flipHorizontal Transition, How will this be applied to subview(Nothing but UIbutton) without effecting to superview(means superview is stable one)?
[UIView transitionFromView:view1 toView:view2
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
/* do something on animation completion */
}];
Make sure you replace view1 with the name of your button you want to flip, and view2 with the view you want the button to be replaced with. You can just put your Button for both of them so it will flip around with no side effects if you like.
I'm a newbie of Xcode and Objective-c. Recently I wanna do a task about popping up tableviews. When a button is pressed, the tableview should pop up from the bottom of the screen. The tableview will contain just a few items so I don't wanna it occupy full screen. I read the manual and found UIModalPresentationStyle, but it seems not fulfill my requirements. So what's the more accurate methods I can use?
While #Bharat J's answer is correct, those methods are deprecated in iOS 4.0.
The latest and greatest implementation is + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
Implemented as:
[UIView animateWithDuration:0.5 animations: ^{
tableView.frame = newFrame;
}
];
You can use below code to create an animation block . Set the frame for the table view as (0,480,320,0) When you hit a button change the frame of the table view in the animation block and make it to CGRectMake(0,200,320,280) or something .
[UIView beginAnimations:#"AnimateTableView" context:view];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
tableView.frame = CGRectMake(0, 200 , 320, 280);
[UIView commitAnimations];
The same animation block for hiding it again but with the frame again begin set to CGRectMake(0,480,320,0). This should work in your case .
Another option would be to use a UIActionSheet and add the uitableview as a subview.
Here is a very similar question about how to add a UIPickerview with similar effect.
Add UIPickerView & a Button in Action sheet - How?
I'm trying to animate my detail view controller to transition with a page curl (up/down). I'm trying to achieve a similar effect as the Notes application on the iPad, this transition was also reproduced by CulturedCode in their Things application for iPad.
My problem is that the animation is clipped to the bounds of the Detail View Controller, it doesn't animate into the Master View Controller, therefore limiting the effect. I see that Apple and CulturedCode managed to make this happen, but I'm stumped.
I've tried the following solutions:
self.splitViewController.view.clipToBounds = False;
self.view.clipToBounds = False;
self.tableView.clipToBounds = False;
The only other solution I can think of is discarding the UISplitViewController altogether and creating my own VC programmatically that will mimic the UISVC behavior so that both of the views (former separate view controllers) will share the same Super View.
Thank you in advance, any advice will help.
RR.
A solution it to just set clipsToBounds to NO and bring the details view to the front in it's superview. Like so:
detailsView.clipsToBounds = NO;
[detailsView.superview bringSubviewToFront:detailsView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:detailsView cache:YES];
...
[UIView commitAnimations];
Where detailsView is your container for the details pane. This should do the trick and the details view will animate in front of the master view. I now have my page transition look quite like the Notes app.