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

contentView's origin x bug when showOnNav with rightView #11

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

litt1e-p
Copy link
Contributor

hi wangmchn, I don't know whether it's a bug that contentView's origin not starts with x:0 when I set showOnNav with a rightView. So I make a PR with some color to mark their frames, just like example

In my solution:

public class MenuView: UIView, MenuItemDelegate {

    // MARK: - Public vars
    override public var frame: CGRect {
        didSet {
            guard contentView != nil else { return }
// FIXME: - reset contentView's x will cause a bug that contentView won't start from x: 0, remove them and works!
/**
            // Make the contentView center, because system will change menuView's frame if it's a titleView.
            if (contentView.frame.origin.x + contentView.frame.width / 2) != (bounds.origin.x + bounds.width / 2) {
                var contentFrame = contentView.frame
                contentFrame.origin.x = bounds.origin.x - (contentFrame.width - bounds.width) / 2
                contentView.frame = contentFrame
            }
*/
        }
    }

I know that adding those codes' reason, but contentView still center its frame after I remove those codes, I wonder whether some code has fixed it. My PR project will show the bug, you can check it out and remove those codes to test it. Thanks.

@wangmchn
Copy link
Owner

Hey,sorry for the bug and carthage problem. Cause I have some works to do with my thesis(it's important),I will check it later.

Sorry again.

发自我的 iPhone

在 2016年5月24日,11:38,litt1e-p [email protected] 写道:

hi wangmchn, I don't know whether it's a bug that contentView's origin not starts with x:0 when I set showOnNav with a rightView. So I make a PR with some color to mark their frames, just like

In my solution:

public class MenuView: UIView, MenuItemDelegate {

// MARK: - Public vars
override public var frame: CGRect {
    didSet {
        guard contentView != nil else { return }

// FIXME: - reset contentView's x will cause a bug that contentView won't start from x: 0, remove them and works!
/**
// Make the contentView center, because system will change menuView's frame if it's a titleView.
if (contentView.frame.origin.x + contentView.frame.width / 2) != (bounds.origin.x + bounds.width / 2) {
var contentFrame = contentView.frame
contentFrame.origin.x = bounds.origin.x - (contentFrame.width - bounds.width) / 2
contentView.frame = contentFrame
}
*/
}
}
I know that adding those codes' reason, but contentView still center its frame after I remove those codes, I wonder whether some code has fixed it. My PR project will show the bug, you can check it out and remove those codes to test it. Thanks.

You can view, comment on, or merge this pull request online at:

#11

Commit Summary

menuViews frame origin.x bugfix control menuView as subView of navigationBar menuViews frame origin.x bugfix
control menuView as subView of navigationBar
hows the origin bug when setting the rightView in NavBar
Merge branch 'master' of https://github.com/litt1e-p/WMPageController-Swift
hows the origin bug when setting the rightView in NavBar
File Changes

A .DS_Store (0)
A Example/Use Code/.DS_Store (0)
M PageController/MenuItem.swift (3)
M PageController/MenuView.swift (3)
A StoryboardExample/.DS_Store (0)
M StoryboardExample/StoryboardExample/Base.lproj/Main.storyboard (3)
M StoryboardExample/StoryboardExample/ParentController/CustomPageController.swift (7)
Patch Links:

https://github.com/wangmchn/WMPageController-Swift/pull/11.patch
https://github.com/wangmchn/WMPageController-Swift/pull/11.diff

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub

@litt1e-p
Copy link
Contributor Author

all right. waiting for you!

2016年5月24日星期二,Wang Ming [email protected] 写道:

Hey,sorry for the bug and carthage problem. Cause I have some works to do
with my thesis(it's important),I will check it later.

Sorry again.

发自我的 iPhone

在 2016年5月24日,11:38,litt1e-p <[email protected]
javascript:_e(%7B%7D,'cvml','[email protected]');> 写道:

hi wangmchn, I don't know whether it's a bug that contentView's origin
not starts with x:0 when I set showOnNav with a rightView. So I make a PR
with some color to mark their frames, just like

In my solution:

public class MenuView: UIView, MenuItemDelegate {

// MARK: - Public vars
override public var frame: CGRect {
didSet {
guard contentView != nil else { return }
// FIXME: - reset contentView's x will cause a bug that contentView
won't start from x: 0, remove them and works!
/**
// Make the contentView center, because system will change menuView's
frame if it's a titleView.
if (contentView.frame.origin.x + contentView.frame.width / 2) !=
(bounds.origin.x + bounds.width / 2) {
var contentFrame = contentView.frame
contentFrame.origin.x = bounds.origin.x - (contentFrame.width -
bounds.width) / 2
contentView.frame = contentFrame
}
*/
}
}
I know that adding those codes' reason, but contentView still center its
frame after I remove those codes, I wonder whether some code has fixed it.
My PR project will show the bug, you can check it out and remove those
codes to test it. Thanks.

You can view, comment on, or merge this pull request online at:

#11

Commit Summary

menuViews frame origin.x bugfix control menuView as subView of navigationBar menuViews frame origin.x bugfix
control menuView as subView of navigationBar
hows the origin bug when setting the rightView in NavBar
Merge branch 'master' of
https://github.com/litt1e-p/WMPageController-Swift
hows the origin bug when setting the rightView in NavBar
File Changes

A .DS_Store (0)
A Example/Use Code/.DS_Store (0)
M PageController/MenuItem.swift (3)
M PageController/MenuView.swift (3)
A StoryboardExample/.DS_Store (0)
M StoryboardExample/StoryboardExample/Base.lproj/Main.storyboard (3)
M
StoryboardExample/StoryboardExample/ParentController/CustomPageController.swift
(7)
Patch Links:

https://github.com/wangmchn/WMPageController-Swift/pull/11.patch
https://github.com/wangmchn/WMPageController-Swift/pull/11.diff

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#11 (comment)

@wangmchn
Copy link
Owner

Hey, @litt1e-p
I have checked the pr, and it's a bug.
I fixed as the follow:

    // MARK: - Public vars
    override public var frame: CGRect {
        didSet {
            guard contentView != nil else { return }
            // Take rightView / leftView and  contentMargin into consideration
            let rightMargin = (rightView == nil) ? contentMargin : contentMargin + rightView!.frame.width
            let leftMargin  = (leftView == nil) ? contentMargin : contentMargin + leftView!.frame.width
            let contentWidth = CGRectGetWidth(contentView.frame) + leftMargin + rightMargin

            let startX = (leftView != nil) ? leftView!.frame.origin.x : (contentView.frame.origin.x - contentMargin)

            // Make the contentView center, because system will change menuView's frame if it's a titleView.
            if (startX + contentWidth / 2 != bounds.width / 2) {
                let xOffset = (contentWidth - bounds.width) / 2
                contentView.frame.origin.x -= xOffset
                rightView?.frame.origin.x -= xOffset
                leftView?.frame.origin.x -= xOffset
            }

        }
    }

You can see a05b50c for more information.

@litt1e-p
Copy link
Contributor Author

I am glad about you fixed the bug, but I can't pod search for ver 1.3.6?

@wangmchn
Copy link
Owner

Ouch,I forgot pushing it to pod.
Try it now.

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

Successfully merging this pull request may close these issues.

2 participants