Hello. I’m trying to prevent rotation of a specif...
# ios
g
Hello. I’m trying to prevent rotation of a specific uiviewcontroller and i’m not able to override
supportedInterfaceOrientations
Anyone know how to achieve this ?
s
Have you looked at the UIViewController Kotlin file? It may be a function since ObjC properties are more like java properties with getters and setters.
g
yes, I looked into it but there is nothing that match my need
in obj-c, it’s declared like this
Copy code
@property(nonatomic, readonly) UIInterfaceOrientationMask supportedInterfaceOrientations;
according to apple documentation. https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations?language=objc
I’ve manage to block rotation by doing it in the Appdelegate. It match my use case but it’s not very practical
Copy code
@UseExperimental(ExperimentalUnsignedTypes::class)
    override fun application(
        application: UIApplication,
        supportedInterfaceOrientationsForWindow: UIWindow?
    ): UIInterfaceOrientationMask {
        val isIphone = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
        if (isIphone) {
            return UIInterfaceOrientationMaskPortrait or UIInterfaceOrientationMaskPortraitUpsideDown
        }
        return UIInterfaceOrientationMaskAll
    }