AS3 iOS prevent "animated" orientation change - ios

I am working in flash CS5.5 on an app for iOS. I want to get the ipad/iphone to stop animating the orientationChange and just change it directly, is this possible?
I thought this was a solution but it didnt help AS3 - iOS force landscape mode only?.

If you try setting Stage.autoOrients = false;, the flash.events.StageOrientationEvent.ORIENTATION_CHANGE will never fire. That's helpful for disabling orientation changes altogether, but not for your issue. While I haven't tried it myself, you may be able to listen to the event:
flash.events.StageOrientationEvent.ORIENTATION_CHANGING
You may be able to call event.preventDefault() in that listener to stop the actual rotation from occuring. Then you can manually set it yourself:
Stage.setOrientation(StageOrientation.ROTATED_RIGHT);

have you tried the SO answer: Disable orienation change rotation animation ?
the code from that answer that goes in the view-controller that is the home for your flash CS5.5 or air 3.5 is:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[UIView setAnimationsEnabled:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView setAnimationsEnabled:NO];
return TRUE; /* Your original orientation booleans, in case you prevent one of the orientations */
}
that code makes use of native iOS UIViewController functions that can be overridden. you would have to have a native iOS objective C class that overrides UIViewController, and then you could insert the code above. calls are made when the device is rotated to these as part of view controller life cycle.

Related

iOS 16 prevent UIViewController from rotation

I have an UIViewController that supports all UIInterfaceOrientationMasks
But, in one certain case I need to prevent it from rotation
Before iOS 16 i was just handling this case like this
override var shouldAutorotate: Bool {
return !screenRecorderIsActive
}
And everything was working fine
After update to iOS 16 my controller keeps rotating and I can't find a way to fix it
In my case, I need to prevent auto rotation not based upon a particular orientation, but rather based upon what you're doing in the app and what kind of hardware your device has. And, I need to continue to support iOS versions all the way back to 9.3. These updates forced me to to do the following:
The new functions aren't available back in 9.3, so I have to do some checking if the version of iOS is 16.x. If so, then I had to implement supportedInterfaceOrientations so that the current user interface orientation is queried and only returns TRUE if the orientation requested is the same as the current user interface orientation. In other words, don't allow a change.
Also, since both returning from the background or rotations or events from other view controllers can change my logic choice for which orientations are allowed, I had to be sure to call the setNeedsUpdateOfSupportedInterfaceOrientations method when returning from the background or any other time I needed to prevent auto rotation.
Again, I had to wrap this code in iOS version checks. Finally I had to implement things the old way for older versions of iOS.
I was very disappointed that such a breaking change was introduced. Yes, the methods were deprecated for a long time, but the new methods weren't introduce until 16.0 - and even more critically, my code does different things when using the front landscape camera now available on the iPad 10, so I had to wait until I had a unit in my hands to uncover these issues.
Quoted from the iOS 16 release notes:
[UIViewController shouldAutorotate] has been deprecated is no longer
supported. [UIViewController attemptRotationToDeviceOrientation] has
been deprecated and replaced with [UIViewController
setNeedsUpdateOfSupportedInterfaceOrientations].
Workaround: Apps relying on shouldAutorotate should reflect their
preferences using the view controllers supportedInterfaceOrientations.
If the supported orientations change, use `-[UIViewController
setNeedsUpdateOfSupportedInterface
To implement dynamic supported interface orientations, you can use some code like this:
var screenRecorderIsActive: Bool {
didSet {
setNeedsUpdateOfSupportedInterfaceOrientations()
}
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if screenRecorderIsActive {
return [.landscape] // For example, or a variable representing the orientation when the condition was set
}
return [.all]
}

Callback when interface rotation ENDED in iOS 9?

I haven’t seen a definitive answer to this question yet, lots of noise around the iOS 8 changes, but I’d like to address it for iOS 9:
What is the correct way to get a callback after an interface orientation change ENDS?
As of iOS 9, didRotateFromInterfaceOrientation: has been deprecated, and the official documentation tells us to use viewWillTransitionToSize:withTransitionCoordinator instead. This gives us (through the transitionCoordinator) a means of animating alongside the transition, and a completion block, but no direct callback for the bona fide ‘end’ of the transition.
The other method from the transitionCoordinator is notifyWhenInteractionEndsUsingBlock:, but this appears to report the end of the interactive part of the transition, not the entire thing.
So, is the “official” way to do this to implement animateAlongsideTransition:completion, and simply ignore the animation option?
I realise we can still use good old didRotateFromInterfaceOrientation:, but it’s always better to modernise where possible.
Yes, you can ignore animation option, just use 'nil' for it.
Example from WWDC 2014 'View Controller Advancements in iOS 8':
- (void) viewWillTransitionToSize:(CGSize)s withTransitionCoordinator:(UIVCTC)t
{
orientation = [self orientationFromTransform: [t targetTransform]];
oldOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self myWillRotateToInterfaceOrientation:orientation duration:duration];
[t animateAlongsideTransition:^(id <UIVCTCContext>) {
[self myWillAnimateRotationToInterfaceOrientation:orientation duration:duration];
}
completion: ^(id <UIVCTCContext>) {
[self myDidAnimateFromInterfaceOrientation:oldOrientation];
}];
}
Works fine with iOS 9.

How to perform some action when rotate screen in iOS?

I am trying to create an action when I turn the screen of my device.
In the Apple documentation I have read that you have to use this method:
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
println("I rotate.")
self.tabBar.frame = CGRectMake(0, 80, self.view.bounds.size.width, self.view.bounds.size.height);
}
But when I turn the screen in the log does not print "I rotate."
EDIT:
These are the settings of the project:
The willRotateToInterfaceOrientation function is deprecated in iOS 8 as you can see in the Apple documentation here. See the discussion here on StackOverflow.
From the documentation, you also are supposed to call super:
Your implementation of this method must call super at some point during its execution.
That shouldn't cause the issue you are seeing though. Double check that your target allows rotation. Go to your project, select the target, and under general make sure you have other orientations checked. If you have only one orientation checked then you can rotate the device, but it won't change orientation.
Where is this method? It will only be called if in a subclass of UIViewController.
EDIT: It seems that willRotateToInterfaceOrientation is not called in a UITabBarController subclass (which seems to be what you're using) in iOS 8, but it is called in iOS 7. Even though the method is deprecated, it is still called in a direct subclass of UIViewController in iOS 8. But, for iOS 8 and above, it is preferable to use the new viewWillTransitionToSize:withTransitionCoordinator:.

How to create a landscape-view only ios application

I want to create an iOS app that can only work on landscape-view mode.
I Googled how to do that, and end up with supportedInterfaceOrientations method
Here's my attempt:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
I tried to put the above code on viewController.m and AppDelegate.m, but it didn't seem to work
Thanks, any opinion will be much appreciated
You don't need to write any code to run app which supports landscape mode only. Just select app target and uncheck portrait and portrait upside down orientation and make sure landscape orientation is checked.
It seems as though you want to programmatically change the orientation of your application. This can be done by any ViewController by implementing one method.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
That should force the view to auto-rotate in the direction you want it.
When you use -supportedInterfaceOrientationForPresentation it simply states that the returned interfaces can be used, not necessarily that they should be used.
When you use -preferredInterfaceOrientationForPresentation it says that this is orientation that I want, and that the ViewController should switch to it.

Can I disable autorotation animations and still get rotation notifications?

I want to implement all my own rotation animations but if I only return YES to UIInterfaceOrientationPortrait in shouldAutorotateToInterfaceOrientation:, I no longer get didRotateFromInterfaceOrientation: and willRotateFromInterfaceOrientation: notifications.
Can I get notifications for rotations while also disabling the default rotation animations?
You should still be able to subscribe to UIDeviceOrientationDidChangeNotification even if you've disabled view controller autorotation via shouldAutorotateToInterfaceOrientation:.
I know this question is a bit old, but just thought I'd add a link to a tutorial I found when I was in the same situation you were (wanting to get notifications for device rotation without allowing views to rotate).
This tutorial gives a nice and simple overview of how to handle device rotation using UIDeviceOrientationDidChangeNotification.

Resources