Disable Default Animation from Portrait to Landscape

Disable default animation from Portrait to Landscape

Sorry there is no way to control the rotation animation. This is done way outside of your app, deep in the window manager where it takes a screenshot of the current screen, resizes and rebuilds the UI behind it, and then runs a built-in animation to transition from the original screenshot to the new rebuilt UI. There is no way to modify this behavior when the screen rotation changes.

Disable effects on rotation screen android

You should force the screen orientation to portrait (or landscape) and handle rotation using accelerometer. I guess this is the only way to display a camera preview without recreating surfaces and other UI hickups. At least this is the way a default camera application handles rotation.

Then You can add custom rotation animations to your icons, relayout UI, etc.

How to turn off screen rotation animation while switching from landscape to portrait and vice versa

The idea is that, static lock the app's screen orientation ,

then detect screen orientation changes,

finally, DIY your screen rotation logics.

no animation is also OK.

  • Firstly, do as @dengST30's answer

and simple SystemChrome.setPreferredOrientations is sufficient

  • Secondly, detect screen orientation changes

in iOS, native code again:

register notification:

NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil)

rotation detected:

@objc func rotated() {
if UIDevice.current.orientation.isLandscape {
print("Landscape")
}
else if UIDevice.current.orientation.isPortrait {
print("Portrait")
}
}

  • thirdly, you can skip or speed up screen rotation animation, now

write your own animation and UI transform code now.

Disable css animation on orientation change

The only way that I can think of to do that in pure CSS involves the use of a single animation.

This way the browser asumes the animation has finished, and won't trigger it again.

In one orientation, we will use half of the animation, beginning at the middle, and ending at the end.

In the other orientation, we will begin also at the middle, but we will execute it in reverse and end at he beginning

@keyframes dual {  from {    margin-left: 0;  }  49.9% {    margin-left: -100vw;    margin-top: 0;  }  50% {    margin-left: 0;    margin-top: -100vh;  }  to {    margin-top: 0;  }}@media only screen and (orientation: portrait) {  .element {    animation-name: dual;    animation-duration: 2s;    animation-delay: -1s;  }}@media only screen and (orientation: landscape) {  .element {    animation-name: dual;    animation-duration: 2s;    animation-delay: -1s;    animation-direction: reverse;  }}
.element { width: 100px; height: 100px; background-color: lightblue;}
<div class="element"></div>

In 7.3/9/2+ Swift how to disable rotation animation, when device rotates?

You can use Method swizzling.

This means to are going to change calls to "viewWillTransitionToSize" on any view controller in your application to call "genericViewWillTransitionToSize" instead.

This way you do not have to use subclass, or repeated code over your application.

With that sad, you should be very carful with swizzling, with great power comes great responsibility. Put the class in a place that you, or the next programmer after you, will know how to find it, when he will want to return the rotation animations to view controllers.

extension UIViewController {

public override static func initialize() {
struct Static {
static var token: dispatch_once_t = 0
}

dispatch_once(&Static.token) {
let originalSelector = #selector(UIViewController.viewWillTransitionToSize(_:withTransitionCoordinator:))
let swizzledSelector = #selector(UIViewController.genericViewWillTransitionToSize(_:withTransitionCoordinator:))

let originalMethod = class_getInstanceMethod(self, originalSelector)
let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)

let didAddMethod = class_addMethod(self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))

if didAddMethod {
class_replaceMethod(self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
}

// MARK: - Method Swizzling
func genericViewWillTransitionToSize(size:CGSize,
withTransitionCoordinator coordinator:UIViewControllerTransitionCoordinator)
{
self.genericViewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
coordinator.animateAlongsideTransition(nil, completion:
{_ in
UIView.setAnimationsEnabled(true)
})
UIView.setAnimationsEnabled(false)
}
}

Disable orientation change rotation animation

If I remember correctly (this is always the sort of thing I have to play around with for a moment to get right) willRotateToInterfaceOrientation:duration: and willAnimateRotationToInterfaceOrientation:duration: are both inside the animation block, while didRotateFromInterfaceOrientation: runs after the animation block. I believe you would need to lay out your views in willRotate so they appear in the position in which they would appear after the rotation had they not rotated (if that makes sense). This way the animation will animate them from their original (correct) layout to the new (rotated) layout in the opposite direction that the device rotates, creating the appearance of no animation. Once the rotation is complete, you can lay out your views, without animation, in didRotate, giving the impression that they rotate instantly.

Clear as mud, no?



Related Topics



Leave a reply



Submit