Flip view in iphone with navigation bar - iphone

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].
`

Related

how to remove a view?

I have an iphone application in which i am adding a view controllers view with an animation like flipfrom left.I was doing it with navigationbarbutton item.when clicking on it i was adding a view controllers view to my rootview.and changing the button amd in that action i am removing that view and adding the previous button like that.but the pbm i need to remove that info view with in a button action inside that view.here is my code for the flipanimation.`
- (void)backPressed1
{
InfoViewController *infoviewcontroller = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.95];
//[UIView beginAnimations:nil context:NULL];
//[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
//CGRect frame=CGRectMake(0,0,320,480);
[rootview removeFromSuperview];
//[infoviewcontroller.view setFrame:frame];
//selfhelpscoresAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate];
[infoviewcontroller viewWillAppear:YES];
[self.view addSubview:infoviewcontroller.view];
[UIView commitAnimations];
UIImage *buttonImage = [UIImage imageNamed:#"information_btn.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 42, 32);
[button addTarget:self action:#selector(backpressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = customBarItem;
//UILabel *label =[[[UILabel alloc]init]autorelease];
self.navigationItem.title=#"Tutorial";
//label.text = #"";
//self.navigationController.title = #"";
[customBarItem release];
}
-(IBAction)backpressed
{
InfoViewController *infoviewcontroller = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.95];
//[UIView beginAnimations:nil context:NULL];
//DailypercentageViewController *pieChart = [[DailypercentageViewController alloc] initWithNibName:#"DailypercentageViewController" bundle:nil];
//[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
//CGRect frame=CGRectMake(0,0,320,370);
[infoviewcontroller.view removeFromSuperview];
[self.view addSubview:rootview];
[UIView commitAnimations];
//[rearView setFrame:frame];
//[pieChart viewDidAppear:YES];
UIImage *buttonImage1 = [UIImage imageNamed:#"information_btn.png"];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setImage:buttonImage1 forState:UIControlStateNormal];
button1.frame = CGRectMake(0, 0, 42, 32);
[button1 addTarget:self action:#selector(backPressed1) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem1 = [[UIBarButtonItem alloc] initWithCustomView:button1];
self.navigationItem.rightBarButtonItem = customBarItem1;
[customBarItem1 release];
//UILabel *label1 =[[[UILabel alloc]init]autorelease];
self.navigationItem.title=#"";
//label1.text = #"Home";
//self.title= #"Home";
}
`my problem is how i can remove this infoview and came back to the rootview from with in the button action from the infoview?

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];

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!

How to add UIview animation transition in MailComposerViewController?

I am using the following code:
- (void)flip
{
MailComposerViewController *mailView = [[MailComposerViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:window
cache:YES];
[mtController.view removeFromSuperview];
//[self.window addSubview:[mailComposer view]];
[self presentModalViewController:mailView animated:YES];
[UIView commitAnimations];
[mailView release]
}
here mtController is a navigation controller (XIB file). I removed it and I add mailview, but the simulator does not show it. What am I doing wrong?
What are you trying to do? Less Vague Questions Is A Good Thing™. Are you trying to use a standard Mail compose controller and use it to flip over instead of present normally?
If so, you can do this:
MailComposerViewController *mailView = [[[MailComposerViewController alloc] init] autorelease];
mailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mailView animated:YES];

Flip views in 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