iOS - Problem to open frame(other view) in view - iphone

I have a view, and a button in this view. When I press this button I need open other view as a frame. Searching I found this post: iOS -- how do you control the size of a modal view controller?
I modify this and I doing this in a IBAction connected to a button:
View2Controller *screen = [[View2Controller alloc] initWithNibName:nil bundle:nil]; //Line add
UIView *myHalfView = [[UIView alloc] initWithFrame:screen.view.frame]; //Line modified by me
[self.view addSubview:myHalfView];
CGRect offScreenFrame = myHalfView.bounds;
offScreenFrame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.frame));
[UIView beginAnimations:nil context:nil];
myHalfView.center = CGPointMake(myHalfView.center.x, myHalfView.center.y - myHalfView.bounds.size.height);
[UIView commitAnimations];
[myHalfView release];
But when I press that button nothing happens. I've verified the code runs in debug it step by step.
Thanks.

Take a peak at this it's golden... read the comments in there as well.
http://humblecoder.blogspot.com/2009/04/iphone-tutorial-navigation-controller.html

Your View2Controller is initialized without a nibname?
I typically have a xib I built in Interface Builder in and do the following (have the view in the xib be whatever size you want by default if it doesn't change):
MyViewController* controller = [[MyViewController alloc]initWithNibName:#"MyViewController" bundle:nil];
[navigationController.view addSubview:controller.view];
//manipulate controller.view here
[controller release];

Thanks all for the replies. Finally I do this and works:
First in my IBAction:
View2Controller* modalViewController = [[[View2Controller alloc] initWithNibName:#"View2Controller" bundle:nil] autorelease];
[self.view addSubview:modalViewController.view];
Then in View2Controller.m in viewDidLoad:
[self.view setBackgroundColor:[UIColor clearColor]];
[UIView beginAnimations:nil context:nil];
[self.view setFrame:CGRectMake(0, 1024, 128, 600)];
[UIView setAnimationDuration:0.75f];
[self.view setFrame:CGRectMake(0, 404, 128, 600)];
[UIView commitAnimations];

Related

can not scroll table up and down after using animation and a navigation bar disappears

My first view contains a button and after pressing a button, i will end up with the second view. what I have done is
FirstViewController.m
- (void)pushToWishList {
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:#"SecondView" bundle:nil ];
[UIView beginAnimations:#"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view addSubview:controller.view];
[UIView commitAnimations];
}
SecondViewController is an UIViewController such that :
SecondViewController.h :
#interface SecondViewController :
UIViewController
SecondViewController.m
self.navigationController.navigationBarHidden = NO;
self.navigationItem.hidesBackButton = NO;
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
What is happening is the top navigation is disppearing and the UITableView in my second view can not be scrolled up and down. My program is crashed whenever I try to do this.
Please advice me on this issue. Any comments are welcomed here.
First off its easier to not addSubview: just use this code to turn your page:
- (IBAction)myCart:(id)sender; {
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:viewController animated:YES];
}
This will allow your tableView to scroll! Also, your method return type is void, if you are using a button to call this method, you need to change the return type to IBAction which works for buttons.

Switching View through a function

I'm working on an iPhone/iPad application and trying to switch views through a function call, not by a button. I've seen lots of sources switching views triggered by a button, but there's nothing that explains how to switch views triggered by a function. I tried to do this on my own, but it failed. Here's the code that I tried:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.webview == nil) {
self.webview = [[MainViewController alloc] init];
/* webview initialized with storyboard */
if (self.view.superview == nil) {
[self.view insertSubview:self.webview.view atIndex:0];
}
[storyboard release];
}
}
This is viewDidLoad of the viewController.m. First, it shows WebView.
- (void)changeView {
self.normview = [[AlternateViewController alloc] init];
/* normview initialized with storyboard */
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.webview viewWillDisappear:YES];
[self.webview viewDidDisappear:YES];
[self.webview.view removeFromSuperview];
[self.view insertSubview:self.normview.view atIndex:0];
[self.normview viewWillAppear:YES];
[self.normview viewDidAppear:YES];
[UIView commitAnimations];
}
And when this changeView function (in a viewController.m) is called, It should change the view from webview to normview (actually, it works fine when the same code is triggered by a button). But when I call this function in other file (not viewController.m), such as
ViewController *viewcontroller = [[ViewController alloc] init];
[viewcontroller changeView];
It doesn't work. Anyone can give a clue to solve this or an alternative way? (ps. I'm testing on iPad.)
You can switch views with this function:
YourView *screen = [[YourView alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
You can set the modaltransitionstyle to your willings.
Don't forget to import your headerfile at the top of your class.
#import "YourView.h"

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

How to make a Subview pop-up from an action in UITableviewController

I would like to pop-up a subview pop-up from one of the actions performed by a button placedon a tableview controller.
I initially added a sub-view(initally hidden below the screen) and later want to animate it to
animate and pop-up.
Here is the code for the button action
-(IBAction) finalShareVerse: (id) sender
{
NSLog(#"finalShare Button");
UIView *tempView;
CGRect tmpFrame;
tempView = [[[UIView alloc] initWithFrame:CGRectMake(0, 490, 320, 90)]
autorelease];
[tempView setBackgroundColor:[UIColor blackColor]];
[tempView setAlpha:.87];
[self.view addSubview:tempView];
tmpFrame = tempView.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
tmpFrame.origin.y=390;
self.view.frame=tmpFrame;
[UIView commitAnimations];
}
The problem is that now the parent controller gets animated and popped down instead of
the subview to be popped up.
Is there a way to specify the animation to trigger on only the sub view.
I am new to iPhone app dev.. Please advise.
If I understand correctly, the problem is the line:
self.view.frame=tmpFrame;
You are applying the change of position to the view rather than the tmpView

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!