i developing an iPad app in which i working with images.The application is worked fine in portrait mode when application launched in portrait mode but it gives me ridiculous problem with frames when app i launched in landscape mode. My all functionality already written in "shouldAutorotateToInterfaceOrientation" this method. If i able call this method then it will remove all problem of frames.How i call shouldAutorotateToInterfaceOrientation method in my application in any function?
You don't call shouldAutorotateToInterfaceOrientation: yourself. UIKit sends this message to your view controller in order to know if the view controller should be rotated or not. Move your layout code from shouldAutorotateToInterfaceOrientation: to willRotateToInterfaceOrientation: and it should work.
Check out the UIViewController Class Reference.
shouldAutorotateToInterfaceOrientation:
Your implementation of this method should simply return YES or NO based on the value in the interfaceOrientation parameter. Do not attempt to get the value of the interfaceOrientation property or check the orientation value reported by the UIDevice class. Your view controller is either capable of supporting a given orientation or it is not.
Related
I have a app which i want to display in portrait mode. But I only want to show one view in both modes.
I have do this for iOS5 . But in iOS6,i can't able to do this.
I also tried many codes to solved it.
i use navigation in my app & rotate only one view in both mode is not possible in ios6. Either you fixed your rotation for a view or rotate whole app. Am i right?
How can I solve this problem?
in ios6 have you trying with this in plist like bellow image:-
and you can also set at xcode->projectname->summary:-
From Apple's iOS 6 SDK Release Notes:
Autorotation is changing in iOS 6. In iOS 6, the
shouldAutorotateToInterfaceOrientation: method of UIViewController is
deprecated. In its place, you should use the
supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.
More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult
their children to determine whether they should autorotate. By
default, an app and a view controller’s supported interface
orientations are set to UIInterfaceOrientationMaskAll for the iPad
idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone
idiom.
A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change
over time. The system asks the top-most full-screen view controller
(typically the root view controller) for its supported interface
orientations whenever the device rotates or whenever a view controller
is presented with the full-screen modal presentation style. Moreover,
the supported orientations are retrieved only if this view controller
returns YES from its shouldAutorotate method. The system intersects
the view controller’s supported orientations with the app’s supported
orientations (as determined by the Info.plist file or the app
delegate’s application:supportedInterfaceOrientationsForWindow:
method) to determine whether to rotate.
The system determines whether an orientation is supported by intersecting the value returned by the app’s
supportedInterfaceOrientationsForWindow: method with the value
returned by the supportedInterfaceOrientations method of the top-most
full-screen controller. The setStatusBarOrientation:animated: method
is not deprecated outright. It now works only if the
supportedInterfaceOrientations method of the top-most full-screen view
controller returns 0. This makes the caller responsible for ensuring
that the status bar orientation is consistent.
For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new
autorotation behaviors. (In other words, they do not fall back to
using the app, app delegate, or Info.plist file to determine the
supported orientations.) Instead, the
shouldAutorotateToInterfaceOrientation: method is used to synthesize
the information that would be returned by the
supportedInterfaceOrientations method.
If you want your whole app to rotate then you should set your
Info.plist to support all orientations. Now if you want a specific
view to be portrait only you will have to do some sort of subclass and
override the autorotation methods to return portrait only.
See this example How to force a UIViewController to Portrait orientation in iOS 6
EDIT:
Solutions:
#implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
#end
I am updating my app for iOS 6 and having issues with the changes to autorotation. My app has a bunch of view controllers and all of them should only support the portrait layout except 1 which should support all 3 orientations except upside down.
If I add the application:supportedInterfaceOrientationsForWindow: method to the app delegate do I have to add conditions there to check if im displaying the one VC I want to be able to rotate?
The documentation states that if I implement supportedInterfaceOrientations on a VC it should override the app delegate method but this doesn't appear to be the case. I have an log statement in the method on the child VC and it is called once when the VC loads but its not called when I rotate the device, but the method in the app delegate is.
If I completely remove the method from the app delegate the orientation of my VC's seems to be completely dependent on my apps supported interface orientation settings. This of course seems to be due to the method supportedInterfaceOrientations being called once on creation of the VC but never when the device is rotated.
Does anyone have any ideas or suggestions? It would be much appreciated.
Replace
[window addSubview:viewController.view];
with
window.rootViewController = viewController;
You also need to override - (BOOL) shouldAutorotate and return "YES". This makes it so you declare what orientations your VC supports with "supportedInterfaceOrientations" and then on rotation it should call "shouldAutorotate". If you have any navigation controller or tabbar you may need to subclass those to do the same thing within them. I had this issue recently myself.
try this...
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
// here to implement landscope code
}
else
{
// here to implement setframePortrait
}
}
Since the built-in iOS UIAlertView doesn't give us the ability for skinning, I've built my own UIAlertViewCustom class, which I'm using instead. Any of my view controller can display an instance of UIAlertViewCustom in the same that UIAlertView would be used, except my version allows for skinning graphics/fonts/colors, etc.
My UIAlertViewCustom class works by creating a new key window and root view controller. I then draw my message view on this new root view controller. (The view controller that chose to display the message is seen in the background just like you'd see with UIAlertView.
All of this is working perfectly. There is one piece of functionality that I'd like to implement but haven't figured out how to. I'd like each instance of UIAlertViewCustom to know whether or not it should auto-rotate when the device orientation changes. Of course, I want to know which orientations the view controller beneath (the view controller that created the instance of UIAlertViewCustom and displayed it) supports? If it supports portrait only, then I will not auto-rotate the UIAlertViewCustom, etc.
I don't want each view controller to have to pass in a supported orientation property to each instance of UIAlertViewCustom. I would just like each instance of UIAlertViewCustom to be able to figure out if it should auto-rotate or not.
Any help would greatly be appreciated!
I would try this in your view controller class:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [[view superview] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
I'm not sure if it's going to work, but that is where I would start. This is necessary because the default implementation for this returns YES for UIInterfaceOrientationPortrait and everything else is NO.
Another small thing. Apple has reserved the prefixes that it uses (NS, CF, CA, UI, etc...) and your custom classes shouldn't use them.
EDIT Changed [self superview] to [view superview]
I know the app delegate can say "yo man, I want thais new landscape orientation!" or "no thanks, don't want landscape!" and then the device won't do it.
How to implement this?
The active view controller's shouldAutorotateToInterfaceOrientation: method determines whether the interface will rotate.
For launch, there is a key in your Info.plist file that needs to be set if you want to be able to launch in orientations other than portrait.
I prefer to get the orientation notification by registering UIDeviceDidChangeOrientationNotification. The delegate of UIViewController about orientation always confuses me. I prefer to control the animation effect by myself.
i need to draw PortraitImage or LandscapeImage when my costomNavigation has been change to portrait or landscape.
You need to override willRotateToInterfaceOrientation:duration: in your UIViewController. This will give you a call every time the app changes its orientation.
You can detect orientation by using the UIDevice Class, as shown here:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/orientation
You need to use the methods
- (void)beginGeneratingDeviceOrientationNotifications
and
- (void)endGeneratingDeviceOrientationNotifications
That should probably work.