I am working on an application where I want the view to change quite a lot when the device is rotated. I know that in Interface Builder it is possible to change the orientation and set up the layout there, however when I then rotate it to portrait, the view is the same as for the landscape. Is there a way to set up the two views independently, perhaps using two nibs?
Cheers,
JP
If you're after switching view controllers on orientation changes, like when the iPod app shows it's coverflow view, the following post will help:
http://rndnext.blogspot.com/2009_06_01_archive.html
I don't know if you can do it in IB, but I know you can do it in code. You need to observe the UIDeviceOrientationDidChangeNotification Notification:
(in viewDidLoad...)
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(updateViewOnRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
....
-(void) updateViewOnRotate:(NSNotification *notification) {
// update the views
}
Related
I have a view with some objects, one of them is a webview where I play a video, this view change the size and the position of the object when the device rotates. The problem occurs when I am playing the video in full screen, if I start watching the video in landscape and while I am watching the video (full screen) I rotate the device and then I hit the done button when I return to the view the objects are not in the position that they should be in that orientation.
I set the position in a function, I call that function in viewdidload and also in willAnimateRotationToInterfaceOrientation but how can I control the rotation while I am watching the video?
You could do something like this:
-(void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerPlaybackDidFinish:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
}
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
[self resizeSubviews];
}
So, when the playback finishes, you call your method to resize your subviews, and by the time the player closes, your view should look correct for the orientation.
You could also register for MPMoviePlayerWillExitFullscreenNotification instead, if that more properly fits your needs.
I am using three20 for displaying thumbnails. It's working perfectly. But I need to resize the thumbnail. Is it possible to resize the thumbnail and Bool shouldAutorotateToInterfaceOrientation is also not supported
I am implement to check the orientation in viewdidload method
TTDeviceOrientationIsPortrait()
TTDeviceOrientationIsLandscape();
But it is not working in shouldAutorotateToInterfaceOrientation method
I am fixing the issue by using NSNotification for orientation
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
and refer the link by changing size
Change thumbs size in TTThumbsViewController
I know that I can return YES to support Landscape mode in shouldAutorotateToInterfaceOrientation. But I would like to display a new view, when the user turn the device into landscape mode, how can I do so? thank you.
Observer this event UIDeviceOrientationDidChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(orientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
A useful technique for just this case is, to present a new modal view controller with a "fade" transition from your current view. You can do this in reaction to UIDeviceOrientationDidChangeNotification as mentioned previously by Aaron.
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
I want to call "presentmodalviewcontroller" when the iPhone / iPod Touch is rotated to landscape mode with a flip animation. When it gets rotated back to portrait, I want to present the first view again, again with the flip animation.
Weren't able to find something working on the web :(
I'm sure you can help me :)
Thanks a lot !
Sebastian
Try listening for the UIDeviceOrientationDidChangeNotification notification:
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
When you get on it, present your controller.
In your UIViewController, accept all interface orientations:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
And your controller will start receiving rotation messages, like:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
and
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Where you can react to rotation and do things like present/dismiss modal viewcontrollers.
I have a quite simple question but the answer is not so easy.
I want to hide a UITabBar when my orientation change.
I looked 2 ways :
Frame way
myAppDelegate.tabBarController.tabBar.frame = CGRectMake(<<bottomOfScreen>>);
Works fine but I have a blank area, so tried to play with tabBarController.view.frame et myViewController.view.frame but I didn't get any good result.
Navigation Controller Way
myOtherVC.hideTabBarWhenPushed = YES;
[self.navigationController pushViewController:myOtherVC animated:NO];
Works but isn't a good solution for my app
Update:
[appDelegate.tabBarController.view removeFromSuperview];
[self.view removeFromSuperview]; [appDelegate.window addSubview:self.view];
self.view.frame = CGRectMake(0,0,480,320);
Works fine but doesn't autorotate anymore (and of course, I didn't change the shouldAutorotate and it always returns YES)
How can I hidde my tabBar and make the current view taking its space ?
Thanks
You can use the current solution combined with:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
to detect rotation. (I think that you combine this with view.transform = CGAffineTransformMakeRotation to make it rotate...?)
Two ways I think you can easily do this would be:
to reload the objects back into the tabBar controller - with the hidesBottomBarWhenPushed set to YES for the viewControllers you want to be hidden.
The other option would be to just make your view the only view for the window when the phone is rotated and then put the tabBarController.view back in the window when the phone is rotated back
Hope this helps