Flip views in iPhone? - iphone

I have a UIView which has a button, On the button's tap I am showing a new UIView which contain a UINavigationBar and a UITableView. Is there any way to animate a flip effect on button's tap and load the view and also vice versa ?

Sure, here is some code that may help
- (void)flipAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
// checks to see if the view is attached
[UIView setAnimationTransition:([logTextView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:[self view] cache:YES];
[UIView setAnimationTransition:([logTextView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:[[self navigationController] view] cache:YES];
if ([logTextView superview])
{
[logTextView removeFromSuperview];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"FTP Log", nil) style:UIBarButtonItemStyleBordered target:self action:#selector(viewFtpLog)];
}
else
{
[[self view] addSubview:logTextView];
[[[self navigationItem] rightBarButtonItem] release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Done", nil) style:UIBarButtonItemStyleDone target:self action:#selector(flipAction:)];
}
[UIView commitAnimations];
}
For you, you might want to get the UIView for your table view. The button is what triggers the flip

Related

Flip view in iphone with navigation bar

I want to include Flip view in my project. I made it like this but cant work properly
and secondary view contains an image veiw
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.leftBarButtonItem = flipButton;
UIBarButtonItem *returnButton = [[UIBarButtonItem alloc]
initWithTitle:#"return"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(returnView)];
self.navigationItem.leftBarButtonItem = returnButton;
and i set the action like this
- (void)flipView{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromTop
forView:[self view]
cache:YES];
[self.view addSubview:secondaryView];
[UIView commitAnimations];
}
- (void)returnView {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:[self view]
cache:YES];
[secondaryView removeFromSuperview];
[UIView commitAnimations];
}
surely as you're putting the code, nothing happens because you're not giving the opportunity to do the flip.
try to MOVE these lines:
UIBarButtonItem *returnButton = [[UIBarButtonItem alloc]
initWithTitle:#"return"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(returnView)];
self.navigationItem.leftBarButtonItem = returnButton;
inside of flipView, after or before the animation. And copy these other lines:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:#"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(flipView)];
self.navigationItem.leftBarButtonItem = flipButton;
inside of returnView. You'll see the change.
I hope to be helpful!
Set [self.navigationController pushViewController:self.secondaryView animated:YES];
instead of [self.view addSubview:secondaryView]; and write
forView:self.navigationController.view cache:NO];
instead of forView:[self view].
`

iPhone View Animation

I am trying to switch views, but I want the animation with the view lifts up and its like a piece of paper folding to see what is underneath.
Any tutorials or examples of how to get that view animation, if it is an animation, would be appreciated.
Actually the view that the maps app uses when you hit the button on the corner.
Something like this should work:
MyViewController *myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
myView.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissModalViewControllerAnimated:)] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:myView];
navigation.modalTransitionStyle = UIModalTransitionStylePartialCurl;
navigation.delegate = self;
[self presentModalViewController:navigation animated:YES];
The key here is the modalTransitionStyle property needs to be set to UIModalTransitionStylePartialCurl before presenting the modal view.
More info here: UIViewController Class Reference (look for modalPresentationStyle, modalTransitionStyle, presentModalViewController:animated:, and dismissModalViewControllerAnimated:).
There are two basic ways of doing this, the old one which is no longer recommended:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:containerView cache:YES];
[containerView addSubview:subview];
[UIView commitAnimations];
And the new one (It uses blocks which are supported from iOS 4 and on):
[UIView transitionWithView:containerView duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [containerView addSubview:subview]; }
completion:nil];

swipe view using UISwipeGestureRecognizer

hi all freind i want ask somthing, i try use label to swipe between views but i cant know the problem?
UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];
-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender{
ThirdQPage* y=[[ThirdQPage alloc]init];
[self.view.superview addSubview:[y view]];
[self.view removeFromSuperview];}
You could do this -
- (void)hideView:(NSTimer *)timer
{
UIView *currentView = (UIView *)[timer userInfo];
[currentView addSubview:self.yourNewView];
return;
}
-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:yourCurrentView cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:#selector(hideView:)
userInfo:yourCurrentView
repeats:NO];
[UIView commitAnimations];
}
You can use the same logic to swipe back from your newView to oldView.
Set label.userInteractionEnabled = YES. The default value for UILabel is NO, therefore all touches are ignored.
userInteractionEnabled A Boolean value that determines whether user
events are ignored and removed from the event queue.
#property(nonatomic, getter=isUserInteractionEnabled) BOOL
userInteractionEnabled
Discussion This property is inherited from the
UIView parent class. This class changes the default value of this
property to NO.

UITableView Navigation Bar "Flickers" on Animation

I have a UIViewController, a "switcher" that will basically just rotate a view from one to another.
It all works great, except that the view that I am transitioning to is a UIViewController which holds a UITableViewController. For some reason, when the animation "flips", the navigation bar is invisible, and once the animation completes the navigation bar just appears.
It really doesn't look good and I was wondering if anyone knew why I might be seeing this and how I could fix it?
Thanks,
--d
EDIT: Adding some code by request!
Switcher viewDidLoad method - Currently Initializing both of the ViewControllers because I thought it may help
[super viewDidLoad];
LogoView *logoController = [[LogoView alloc] init];
self.logoView = logoController;
[self.view insertSubview:logoView.view atIndex:0];
[logoController release];
MainController *vController = [[MainController alloc] init];
self.controller = vController;
[vController release];
switchTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(switchViews) userInfo:nil repeats:NO];
Switcher switchViews method
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.controller.view.superview == nil)
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[controller viewWillAppear:YES];
[logoView viewWillDisappear:YES];
[logoView.view removeFromSuperview];
[self.view insertSubview:controller.view atIndex:0];
[logoView viewDidDisappear:YES];
[controller viewDidAppear:YES];
}
[UIView commitAnimations];
MainController viewDidLoad method
CGRect frame = CGRectMake(0, 0, 320, 410);
FirstLevelController *controller = [[FirstLevelController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.view.frame = frame;
navController.navigationBar.tintColor = [UIColor blackColor];
[controller release];
[self.view addSubview:navController.view];
Inside the FirstLevelController I just add the items to the table view... I've tried adding a navController.title = #"Home", but I am not even seeing the black navbar without text... it's just a big empty space.
Help is muchly appreciated!
Hah! I changed the animation "cache" from YES to NO, and it fixed it! Yay!

iPhone: Animating a view when another view appears/disappears

I have the following view hierarchy
UITabBarController
- UINavigationController
- UITableViewController
When the table view appears (animated) I create a toolbar and add it as subview of the TabBar at the bottom of the page
and let it animate in with the table view. Same procedure in other direction, when the table view disappears.
It does not work as expected.
The animation duration is OK, but somehow not exact the same as the animation of the table view when it becomes visible
When I display the table view for the second time, the toolbar does not disappear at all and remains at the bottom of the
parent view.
What's wrong with it?
- (void)animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[toolBar removeFromSuperview];
}
- (void)viewWillAppear:(BOOL)animated
{
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 44, 0);
[[self tableView] setContentInset:insets];
[[self tableView] setScrollIndicatorInsets:insets];
// Toolbar initially placed outside of the visible frame (x=320)
UIView *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(320, 480-44, 320, 44)];
[toolBar setTag:1000];
[[[self tabBarController] view] addSubview:toolBar];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[toolBar setFrame:CGRectMake(0, 480-44, 320, 44)];
[UIView commitAnimations];
[toolBar release];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDidStopSelector:#selector(animationDone:finished:context:)];
[toolBar setFrame:CGRectMake(320, 480-44, 320, 44)];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
Have you tried just using the table view controller's toolbarItems property? UINavigationController will manage a toolbar for you, updating it with the toolbar items of its current topmost view controller; use the -setToolbarHidden:animated: method in your -viewWillAppear: and -viewWillDisappear: to control the visibility of that toolbar.