Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating to landscape wrongly places the controller #34

Closed
alexandrutomescu opened this issue Oct 28, 2018 · 6 comments
Closed

Rotating to landscape wrongly places the controller #34

alexandrutomescu opened this issue Oct 28, 2018 · 6 comments

Comments

@alexandrutomescu
Copy link

alexandrutomescu commented Oct 28, 2018

Hey, thanks for the great library!

We're considering using it in an existing project. I seem to have managed to customize it fine so far (with rounded corners and shadow). But I cannot seem to set up the landscapeFrame. See this video: https://www.dropbox.com/s/8pxh1rdm56fs1fm/pulluppcontroller.mp4?dl=0 When the phone rotates, the controller is placed somewhere below the screen. When it is fully expanded, it does show up a bit, but its bottom is probably somewhere below the screen bounds. Also, it is aligned next to the left screen edge, even if it should have some trailing space.

I did override

override var pullUpControllerPreferredLandscapeFrame: CGRect

in my own ViewController inheriting from PullUpController. I gave it the value CGRect(x: 10, y: 20, width: 280, height: 100). Is there something else I am missing? Or maybe it is clashing with some existing code?

@alexandrutomescu
Copy link
Author

Looks like adding updatePreferredFrameIfNeeded(animated: true) to override func viewDidLayoutSubviews() solved the problem.

@MarioIannotta
Copy link
Owner

Hi @alexandrutomescu and thank you for your interest in this library.
Looking at your video it looks like your app doesn't support landscape mode because the whole ui doesn't rotate when you rotate the device (you can take the nav bar for reference).
Could you please double check that and let me know?

Thanks,
Mario.

@alexandrutomescu
Copy link
Author

alexandrutomescu commented Oct 28, 2018

Hi, thanks for the prompt reply! Our app does support landscape. For example, see the toolbar which moves along the vertical edge of the video (all four Device Orientations are selected in the project settings). I found a fix, in my comment above, but I don't know if this is a best practice.

Also, I have another question related to landscape. I'm now drawing a shadow under the PullUpController. When I rotate to landscape, I would like the shadow to have exactly the same size as the PullUpController.
But this is not happening correctly. See attached files: correct vertical: Correct vertical and incorrect horizontal:
Incorrect horizontal
Any tip how to get the correct bounds of the PullUpController in landscape? (Also, the misalignment of the shadow at the bottom is probably due to me, but I don't know how to fix the misalignment on the other edges.)

For your reference, since iOS doesn't easily allow both rounded corners and a shadow, I had to use this snippet for the shadow:

   ```
    var shadowBounds = self.view.bounds
    if UIDevice.current.orientation.isLandscape
    {
        shadowBounds = self.pullUpControllerPreferredLandscapeFrame
    }
    
    self.view.layer.shadowPath = UIBezierPath(roundedRect: shadowBounds,
                                              cornerRadius: cornerRadius).cgPath
    
    self.view.layer.shadowColor = UIColor.black.cgColor
    self.view.layer.shadowOpacity = 0.5
    self.view.layer.shadowOffset = CGSize(width: 0, height: 0)
    self.view.layer.shadowRadius = 10
    self.view.layer.masksToBounds = false

Thanks!

@MarioIannotta
Copy link
Owner

Ok, I'm glad you found a way to fix the issue, I'll investigate a little bit more to see if I can do something in the library itself to prevent issues like this.
Regarding the shadow problem, it's not really related to the library and without all the code it's really hard to me to understand what's going on but I'll try to add my two cents anyway.

Did you tried to update the shadowPath in you viewDidLayoutSubviews method?

Something like that:

    override func viewDidLayoutSubviews() {
        // other code..
        view.layer.shadowPath = UIBezierPath(roundedRect: view.bounds,
                                             cornerRadius: 12).cgPath
    }

I've done that in the example project and it works good
simulator screen shot - iphone 8 - 2018-10-28 at 22 39 52

@alexandrutomescu
Copy link
Author

Hi,

Just to let you know that I found the cause of the shadow problem. The issue is on iPhone X and variations. As you see from the second screenshot, my main view controller (see e.g. the MapView) goes only until the notch, but not under (the notch is on the left-hand side). However, the coordinates of the landscape frame of the PullUpController seem to take the x coordinate as starting from under the notch.

The shadow goes outside the bounds of the main view controller and under the notch, because I set self.view.layer.masksToBounds = false (to have the shadow go outside of view with rounded corners). But the PullUpController is clipped (it has less width that what I specify in the landscape frame) so that it stays inside the main view controller. As easy fix is to change the x coordinate of the landscape frame depending on whether we have a notch or not, so that the PullUpController stays fully inside my view controller.

Anyway, I would consider this closed, because it doesn't seem a problem of PullUpController and also seems to be an edge case.

Thanks a lot for your help and for the library!
Alexandru

@qasimmajeed
Copy link

@alexandrutomescu bro can you tell me how did you resolved the landscape issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants