Hi I have a problem when adding a subview when my app is in landscape. When the view gets loaded it is in portrait mode so part of the view is missing and I can see the main view on the right hand side. If I load the subview in portrait mode then rotate the iPhone it rotates to landscape no problem. I have googled this lots and it seems to be a common problem yet I am unable to find a solution. Please can someone help?
This is my code to add the view...
PreferencesViewController *screen = [[PreferencesViewController alloc]initWithNibName:nil bundle:nil];
[self.view addSubview:screen.view];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[UIView commitAnimations];
Thanks :-)
[self.view addSubview:viewSpinner];
viewSpinner.frame = self.view.frame;
[viewSpinner setNeedsLayout];
This works for me (Y)
try to set the frame of the subview
[screen.view setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
Are you creating the preference views controller using a xib? Dont forget to set the parent view to auto resize its subviews, and set the child view's autoresizingmasks so its parent view can auto adjust its height and width appropriately.
Related
Hey guys, I still haven't found an answer to this so I think I'll ask you.
[viewOggetto setFrame:aFrame];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:viewOggetto.view];
[UIView commitAnimations];
this is a simple animation for a view to appear in a position and then go full screen.
My question is: how can I make the content of the view follow the animation as well?
Now I have the view frame animating correctly but everything that is inside the view just appears fullscreen instantly.
Thanks.
It's not entirely clear what you want to happen instead of it appearing full-screen instantly. You mean you want it to fade in? Set the alpha property on the subview to 0 and add it to self.view before you start the animation. Then set the alpha property to 1 within the animation.
but what viewOggetto exactly is? if it's a UIView then why to call viewOggetto.view?
is it a UIViewController?
You call both :
[viewOggetto setFrame:aFrame];
[viewOggetto.view setFrame:aFrame];
assuming it's a UIViewController, try this / prova cosi':
[self.view addSubview:viewOggetto.view]; // you need to have it before to animate it
// initial state of the animation:
[viewOggetto.view setFrame:CGRectMake(160, 240, 1, 1)]; // zoom from center
// viewOggetto.view.alpha = 0; // eventually to add a fadeIn animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// ending state of animation:
// viewOggetto.view.alpha = 1; // restore to 1 to eventually to add a fadeIn animation
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
if it's a UIView just delete ".view" in every "viewOggetto.view" code
ciao,
luca
Just want to add to Jim's answer. UIView animations animate UIViews from one context to another. If the context doesn't exist before the [UIView beginAnimations:nil context:NULL]; then underside effects will happen. The context wont exist if the view hasn't been added to subview.
I have ViewControllers A and B on the navigation stack. A does not support landscape orientation, B does. If the user rotates to landscape while viewing B and then taps the Back button, A is now in landscape. How do I prevent this? Is there a good reason the shouldAutorotateToInterfaceOrientation method of A is not respected?
This is really very annoying thing about view controllers. And It seems to be no fix for autorotation. Maybe, the best would be return NO from B's shouldAutorotateToInterfaceOrientation and then perform view rotation manually. Then it won't affect A.
yes, i hate that too...
all i found to solve it was to do it by myself:
- (void)myAutomaticRotation{
if (A.view.frame.size.width > A.view.frame.size.height) {
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration: 0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
self.view.bounds = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
A.view.frame = CGRectMake(0,0,320, 480);
[UIView commitAnimations];
}
}
you can call myAutomaticRotation in a main/super UIViewController when you navigate to A.view,
and in that same place you should use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
}
where you can check the view used (A,B) and allowing landscape mode just for B...
luca
I'm trying to create a simple animation when switching from a view to another in iPhone.
I have a controller with its view. In the same xib file I placed another view I called viewTracks. I would like to write an action that switches from the default view of the controller to the view viewTracks. This is the code of the action I wrote in my controller:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES];
UIView* sup = [[self view] superview];
[self.view removeFromSuperview];
[sup addSubview:viewTracks];
[UIView commitAnimations];
All I see is that the view does switch, but without any animation. Is there any mistake here? Why do I see the correct switch of view without an the animation I specified?
Thanks!
I would recommend making the the two views you want to switch between be subviews of your view controller's view.
-(void)CallingView2{
SettingsViewController *aSettingsView = [[SettingsViewController alloc] initWithNibName:#"Settings" bundle:nil];
[self setSettingsViewController:aSettingsView];
[aSettingsView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
//setting the animation
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
[self.window addSubview:[settingsViewController view]];
**[[settingsViewController view] setBounds:CGRectMake(0, -30, 320, 480)];**
[UIView commitAnimations];}
I have put the code between the stars in the code where I commit my animation and it works, it moves the view as it should but now the problem is that when i rotate to the view i can see when the view is moving down.
Is it possible to set bounds for the view before it is shown so the user cant see when it is moving 30px down every time he go to settings
Your problem is that you're setting the view bounds within an animation block. The view origin will animate from (0,0) to (0,-30) during the time it takes to perform the flip transition.
Setting your view geometry in the view controller's viewDidLoad would be a better approach.
I have a Custom view. This custom view has two UIImageViews - imageview1 and imageview2.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.00];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(transitionDidStop:finished:context:)];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self cache:YES];
if(frontVisible) {
[imageview1 removeFromSuperview];
[self addSubview: imageview2];
}
else {
[imageview2 removeFromSuperview];
[self addSubview: imageview1];
}
frontVisible = !frontVisible;
[UIView commitAnimations];
The image changes from imageview1 to imageview2 and viceversa but I dont get the flip effect. Instead I see the fading out of one image as the other appears.
Not really sure but I checked the documentation and found this:
Discussion
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.
So it says you have to create a container view in order to make it work properly.
The reason you're not getting the curl transition to work is because the curl transition does not work in the simulator. It shows up as a fade instead.