Disable rotation during textField editing? - iphone

is it possible to disable orientation rotating during textField editing? For example, it's possible to rotate app between portrait and landscape, but if you tap a text field in portrait, you can't rotate to landscape until your done editing? or vice versa if your in landscape?
I'm thinking if there is a way to do this, I'd be implementing it in textFieldDidBeginEditing and textFieldDidEndEditing
any help would be appreciated, thank you

Set your textField delegate to be the view controller. When the textfield lets you know it's going to edit (I believe it's something like - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField) set an iVar to your current orientation (_orientation = self.interfaceOrientation) and set a BOOL iVar(I'd call it _editing) to YES. In the method - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation return NO if it's not the orientation of the iVar and _editing is YES.

Related

Rotation issue of UIAlterView in iOS7

I am using UIAlertView in my application with textField. I launch UIViewController in landscape mode and provide only landscape masking. But when I change the device orientation keyboard is autorotate but UIAlertView is remains same at the position and hide below the keyboard.
It's not possible. I have used both with & without autoresize, even I use storyboard and xib file in all that cases I got correct result. I am not sure but might be you have done something extra in your code.
Attached is my output and which should also be for you.
You can check and resign first responder textfield while auto-rotating and make it first responder once orientation is changed.
You can find method in view's lifecycle, which are called while changing orientation,
[textfieldName resignFirstResponder];
And once new orientation is achieved you can again call it this way,
[textFieldName becomeFirstResponder];

iPhone Orientation Change

I know how to do an orientation change, but lets say you have a view with buttons, labels, ect. The autoresizing distorts and makes the view look strange. What's the accepted way to do this, do I just create a portrait and landscape view. If so where would I actually do the swapping of these views.
Do all kind of resizing and reposition in your layoutSubviews method of UIView.
Once the orientation is changed, your layoutSubviews would be called then you can know the current orientation by using UIDevice class. and reposition your views child accordingly
UIDevice property to be used for getting current orientation .
#propertyic,readonly) UIDeviceOrientation orientation
My sandbox app:
https://github.com/comonitos/programatical_device_orientation
The solution is easy

How to stop rotation on `willRotateToInterfaceOrientation:`

I need a way to force the orientation back to portrait on rotate.
The problem is that I have a Tab bar controller, but only want one of the tabs to autorotate.
So I have allowed rotation on all tabs and now I need a way to intercept a rotation on a tab where I don't want to allow rotation.
I'm guessing I can do this on - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration?
Thanks
Tom
There is no way to force rotation. In case of a UITabBarController you are out of luck. It is an all or nothing situation wrt interface rotation. If one of your tabs cannot rotate then the whole UITabBarController stays in portrait mode fixed.
Maybe this would even work if implemented in all your viewControllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (return ([[self.tabBarController.selectedViewController class] isSubclassOfClass:[TurnableViewController class]]) || UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
This will, however, not turn back your view if you switch back to a non-turnable, until you tilt your device...

Iphone sdk custom uiview orientation issue

I am using custom based uiview controller with uitabbar contains uitableview. I am using image for cell background. I want to do orientation from portrait to landscape but the issue is it is not changing on orientation. I just want to know is there are any special thing for custom uiviewcontroller for orientation?
Thanks in advance
Regards,
sathish
If nothing happens when you rotate the device, you either have the system-wide rotation lock enabled (you checked that, right?), or your view controller isn't returning YES to the alternate orientation in its shouldAutorotateToInterfaceOrientation:, or you're doing something odd with your views that means your view controller isn't getting set as the “frontmost” one and thus isn't getting asked about orientation changes. It'll be easier to narrow that down if you post the code you're using to set up the controller and its view.

Monotouch rotate view in Portrait/Landscape

Can anyone give an example of how to rotate the view of a monotouch application from portrait to landscape and vice versa?
If you set the geometry of your ui elements in Interface Builder, then make sure you set the Autosizing attributes in the Size Inspector (Cmd+3). You can then see how the view will look after rotating by clicking the little "Rotate" button in the upper left of the title bar of your view in Interface Builder.
Once you have all that set up, just override the following method in your ViewController:
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
Now in the simulator, you can rotate all you want and your UI will auto-adapt.
Just so everyone knows, it is now on the views Transform object:
View.Transform.Rotate(3.14159f * 0.5f);
For all you dotnet guys like me that don't want to use anything that is CGAffineTransform, thinking it will break other things, just try it. Worked great for my instance. Rotated the NavigationController.View and everything inside it is perfect.
This is what you can try out.
If you want to change the orientation of the view while touching on the view , then follow the steps
Implement the touchesBegan method inside the view.
In the touchesBegan method check the current device orientation,
[[UIDevice currentDevice] orientation];
If you want to change the orientation then use the CGAffineTransformation method on the view as viewRef.transform = CGAffineTransformMakeRotation(angle);