omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    iPad Orientation Control help

    Pythonista
    4
    44
    10183
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mcriley821
      mcriley821 @cvp last edited by

      @cvp I’m no guru by any means lmao. It takes many crashes for me before I get something working. I’m steadily learning though.

      My only guess on why monkey-patching didn’t work is because we already alloced and inited vc as a regular UIViewController and didn’t create another instance after overwriting the class method. But honestly I’ve never done monkey-patching so I’m not positive what I’m talking about

      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @mcriley821 last edited by

        @mcriley821 But I was overriding an instance method, not a class method. And it worked because the def was called.

        JonB 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @mcriley821 last edited by

          @mcriley821 I just tested with my old code and modal style 0, and it works in the same way as your code with the new objc class. The only difference is that the _cmd 2nd parameter is not accepted.

          1 Reply Last reply Reply Quote 0
          • mcriley821
            mcriley821 last edited by

            @cvp if you do

            print(vc.preferredInterfaceOrientationForPresentation())
            

            you still get 1, but if you

            print(UIViewController.preferredInterfaceOrientationForPresentation())
            

            You get 3.
            Your monkey-patch overwrites the UIViewController object. But if you do

            vc.preferredInterfaceOrientationForPresentation=preferredInterfaceOrientationForPresentation(vc)
            

            The print has an error 'int object is not callable'.
            Maybe it thinks the method is an attribute, and instead of overwriting the function it just makes an attribute

            cvp stephen 2 Replies Last reply Reply Quote 0
            • cvp
              cvp @mcriley821 last edited by

              @mcriley821 you're right. I 🤐 and 😰

              1 Reply Last reply Reply Quote 0
              • stephen
                stephen @mcriley821 last edited by

                @cvp @JonB @mcriley821

                Wow.. ok let me go over this data and ill see what i come up with. im still learning ObjC/Swift. Thank ya'll so much for your input and time im off to crash Pythonista a few times lol i hope we can get this because it would be nice for everyone to have this ability without XCode..

                1 Reply Last reply Reply Quote 0
                • stephen
                  stephen last edited by

                  @cvp @JonB @mcriley821

                  Apple said:

                  @property(nonatomic, readonly) UIInterfaceOrientation preferredInterfaceOrientationForPresentation;
                  

                  Documentation

                  Just to make sure im understanding properly lol..

                  we use preferredInterfaceOrientationForPresentation with 2 or more UIInterfaceOrientation set on our UIViewController to limit rotation but allowing rotation to differ from UIStatusBar. and if we dont set this property it will keep the UIViewController set to the current UIInterfaceOrientation of UIStatusBar UIInterfaceOrientation..

                  Instead of trying to make the View's rotation differ from the status bar. why dont we just control the rotation of UIStatusBar itself? or is that where iPadOS has the issue of ontrolling orientation of apps that supports split-screen multitasking.

                  cvp 1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @cvp last edited by

                    @cvp you cannot monkey patch an objc object, without using the objc runtime (swizzleing). Monkey patching just affects calls in python -- when the system calls a selector it doesn't know anything about the python attribute.

                    There is a way to swizzle in objc, though as I recall, swizzling a single instance is tricky.

                    cvp 1 Reply Last reply Reply Quote 1
                    • cvp
                      cvp @stephen last edited by

                      @stephen wow 🤔🤯🤕🤒

                      stephen 1 Reply Last reply Reply Quote 1
                      • cvp
                        cvp @JonB last edited by cvp

                        @JonB Thanks for your explanation.

                        1 Reply Last reply Reply Quote 0
                        • stephen
                          stephen @cvp last edited by stephen

                          @cvp said:

                          @stephen wow 🤔🤯🤕🤒

                          lol i just read what i put lol it sure is a bit of a mouth full 😂🤣

                          1 Reply Last reply Reply Quote 0
                          • stephen
                            stephen last edited by

                            @JonB would you happen to know of any good tutorials/walkthroughs/guides i can checkout on objc_util..? im kinda grasping it but there just somthing missing for me to fully take her home...

                            1 Reply Last reply Reply Quote 0
                            • stephen
                              stephen last edited by

                              😂 just found this while looking through my list of view controller members lol

                              attentionClassDumpUser_yesItsUsAgain_althoughSwizzlingAndOverridingPrivateMethodsIsFun_itWasntMuchFunWhenYourAppStoppedWorking_pleaseRefrainFromDoingSoInTheFutureOkayThanksBye_
                              

                              about died

                              1 Reply Last reply Reply Quote 0
                              • stephen
                                stephen last edited by

                                😓😴 im at a loss.. i tried:

                                • setInterfaceOrientation
                                • shouldAutorotateToInterfaceOrientation
                                • preferredInterfaceOrientationForPresentation
                                • viewControllerForRotation().setInterfaceOrientation_
                                • setModalPresentationStyle
                                • window_willRotateToInterfaceOrientation

                                the list goes on for a bit lol

                                ill get no errors but also nothing changes

                                1 Reply Last reply Reply Quote 0
                                • JonB
                                  JonB last edited by

                                  Did you implement @mcriley821 's code, along with the alloc().init()? I haven't but mcriley says it works...

                                  stephen 1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp last edited by cvp

                                    The gist in one of my posts used @mcriley821 's code.

                                    The method works but not what @stephen wants.
                                    Perhaps, the used ViewController is not the good one.

                                    1 Reply Last reply Reply Quote 0
                                    • stephen
                                      stephen @JonB last edited by

                                      @JonB @cvp ya iv been mesing with it for just a min and i cant seem to get it to lock, force rotate or anything lol

                                      cvp 1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @stephen last edited by

                                        @stephen you're right. I don't know how to do and that's the reason why I saidthat I let YOU go on 😅

                                        stephen 1 Reply Last reply Reply Quote 1
                                        • stephen
                                          stephen @cvp last edited by

                                          @cvp said:

                                          @stephen you're right. I don't know how to do and that's the reason why I saidthat I let YOU go on 😅

                                          all good i even tried the one JonB mentioned and nothin

                                          1 Reply Last reply Reply Quote 0
                                          • JonB
                                            JonB last edited by

                                            In that case the best option may be to implement a callback on the layout method to re-rotate the view. This could maybe be implemented with a simple Transform.rotate.

                                            stephen 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors