How to rotate view to landscape mode in block-based animation - iphone

My application contains a Tab Bar Controller and Navigation controller.
Its totally in Portrait mode. Now I have a table view in 2nd tab, clicking on each row of table view will push another view controller which will show a graphical chart, now I want this chart to be in landscape mode where as the rest of application is in portrait mode.
I came to know that we have to rotate the view on our own, now my question is how to rotate this new view in landscape mode. I put some UIView animations in viewWillAppear function, but I want the block-based animation to rotate this view to landscape for me and when I go back it rotate back portrait mode.
Thanks in advance !

Check the device orientation and make the rotation depends on it:
[UIView animateWithDuration:0.5f animations:^{ myView.transform = CGAffineTransformMakeRotation(-M_PI * 0.5); } ];

Related

Autoresizing not working in portrait mode

I'm adding a view to view controller in which there are certain components. My project needs to support both orientation.
I designed the view controller using story board in landscape mode. When a button is pressed in the view controller the view is shown using the scaling animation.
It works perfect when its in landscape mode. When its in landscape mode and button is pressed it works perfect and also the rotation also works perfect. But if its in landscape mode and button is pressed the view doesn't get scaled according to the portrait mode and rotation is also a big problem.
I'm using autosizing and not auto layout
Can anyone please help me? Sorry for my bad english.
Any help is appreciated.
Autosizing has never proved to be the best solution for frame changes in orientation modes. Instead, change the frames manually in orientation delegate methods:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
check for your current orientation like:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
// change frames here for portrait mode
}
else
{
// change frames here for landscape mode
}
}

UIView auto resize when transitioning subviews

I am trying to provide rotation support, however when transitioning between two UIViews, the autoResizingMask property appear to be ignored.
Here is a video illustrating the problem:
http://www.youtube.com/watch?v=AWtO7J6YNxA
I currently have each UIView (parent and subviews) set to:
uiView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight );
Also, the parent view has:
self.view.autoresizesSubviews = YES;
It looks like when you return from your Web View (Google page) the two views you mention above are being displayed in PORTRAIT mode but the device is in LANDSCAPE. If so you could just store the two views frame coordinates (x,y,width and height) before you transition to the UIWebView page and restore them when you transition back. Of course you would need to check on the return if the device is in Landscape or Portrait mode.
If you saved the Frame coordinates in PORTRAIT mode and you return to the screen from your UIWebView and the device is in PORTRAIT mode then just restore them with
self.myView.frame = CGRectMake(savedValueOfX,
savedValueOfY,
savedValueOfWidth,
savedValueOfHeight);
If the device is now in LANDSCAPE mode then restore them like this...
self.myView.frame = CGRectMake(savedValueOfX,
savedValueOfY,
savedValueOfHeight,
savedValueOfWidth);

textfield animation in iPad rotation

I'm starting to upgrading a iPhone App to Universal App, and I have a question: when the user rotates the iPad, how can I animate a couple of textfields?
In portrait, they are at the middle of the view, but in landscape, I want them in the right side of the view.
How can I do that animated?
Thanks,
Rui
When the interface is rotating, your view controller's willAnimateRotationToInterfaceOrientation:duration: method will be called. It is called from inside the animation block for the rotation, so changes to any animatable properties should automatically be animated. The implementation should probably look something like this:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
// Move views to the correct positions for landscape orientation
} else {
// Move views to the correct positions for portrait orientation
}
}

How do I initialize a view to an interface orientation?

The problem is that I am launching in-app email and triggering keyboards (via UITextFields) and they are coming up portrait on my landscape app. I am able to rotate it portrait, then rotate it landscape again, observing the black rotation corners animation that occurs when an app rotates from portrait to landscape. Since I've locked out any orientation but landscape right in my shouldAutorotateToInterfaceOrientation() method, the view itself doesn't rotate, which is great. However, when I add these views, the app keeps thinking they are portrait as is evidenced by the UITextField keyboard and in-app email orientation unless I rotate to portrait, then back to landscape (which triggers the autorotate method to return true.
Any suggestions on how I can make this app know it's already in landscape to begin with when I'm adding views?
Update: I had tried setting the status bar orientation, but it does not work for me. I don't know if there's something with the fact that I remove and then add views to the app that is confusing its understanding of the orientation. Do you know how apple objects such as the UITextField and in-app mail determine what orientation to show? Do they simply poll the sharedApplication orientation? The odd thing for me is that it seems like when I remove and add new views, these apple widgets that I've tilted the phone to change to landscape suddenly revert to showing as portrait. i.e. this general sequence of events:
1) app in landscape, trigger keyboard, it shows portrait
2) tilt device to make it go into landscape. close and open keyboard and it's in landscape.
3) remove and add some views.
4) trigger keyboard again, it shows up in portrait
[UIApplication setStatusBarOrientation:animated:] should give you what you want.
Setup Initial interface orientation field in Project plist
Interestingly, I found that setting the status bar orientation at the launch was not enough. Watching the field value, I noticed it was resetting to portrait at various times, such as when returning from canceling an in-app mail. I found making multiple calls to set the status bar seems to address the problem. Thanks for the input, mbehan.
Removing/adding views shouldn't change the status bar orientation; as far as I know, that defaults to the view controller's orientation unless you set it explicitly (and then you have to be careful, because view controllers reset it). You can try using UIStatusBarStyleBlackTranslucent and setting UIViewController.wantsFullScreenLayout on your VCs to see what's going on.
(In the past, I've noticed it getting confused when I add a view to the window directly, on top of a portrait-only view. It seems to work in all other cases though...)
What's your implementation(s) of shouldAutorotateToInterfaceOrientation:?
try this:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Rotate the complete view to look like landscape view
[self rotateToLandscape];
}
and the rotation method;
-(void)rotateToLandscape
{
UIWindow *win = [[UIApplication sharedApplication]keyWindow];
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
[[[UIApplication sharedApplication] keyWindow] setBackgroundColor:[UIColor blackColor]];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
win.transform = CGAffineTransformIdentity;
win.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
win.bounds = CGRectMake(0.0f, 0.0f, 480, 320);
win.center = CGPointMake(160.0f, 240.0f);
[UIView commitAnimations];
}
}

Statusbar orientation changes after dismissing modal view

My statusbar orientation is landscape, I have a cocos2d view that only supports portrait orientation(it is OK since it handles transformations). I have another view that is presented as a modal by cocos2d controller, its orientation is landscape, but whenever I dismiss it, my statusbar orientation somehow changes to portrait, I tried overriding supported orientation methods of container views, but none of them has any effect.
regards
OK, here is how I did it, I thought what messes things up is the fact that orientation of container being different from the view that is presented as modal. So I added another view to contain cocos2d view and presented the modal using that view. The container's orientation is lanscape, so I needed to transform cocos2d view int he load method of its controller.
self.view.transform = CGAffineTransformRotate(self.view.transform, -(M_PI / 2.0));
self.view.frame = CGRectMake(0, 0, 480, 320);
I am still looking for a better way of doing this.