https://kotlinlang.org logo
#ios
Title
# ios
g

gonzooin

03/10/2020, 12:50 PM
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

Sam

03/10/2020, 1:03 PM
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

gonzooin

03/10/2020, 1:11 PM
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
    }
4 Views