首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有堆叠菜单的CosmicMind快速材料库程序自动收费

具有堆叠菜单的CosmicMind快速材料库程序自动收费
EN

Stack Overflow用户
提问于 2016-02-12 22:33:21
回答 1查看 585关注 0票数 1

我在用CosmicMind的资料库。我正在尝试让Menu示例与编程自动收费输出一起工作--在哪里可以找到如何使其工作的示例?

Github上的示例中,我还没有找到使用autolayout的方法。

代码语言:javascript
复制
/// Prepares the FlatMenu example.
private func prepareFlatbMenuExample() {
    let btn1: FlatButton = FlatButton()
    btn1.addTarget(self, action: "handleFlatMenu", forControlEvents: .TouchUpInside)
    btn1.setTitleColor(MaterialColor.white, forState: .Normal)
    btn1.backgroundColor = MaterialColor.blue.accent3
    btn1.pulseColor = MaterialColor.white
    btn1.setTitle("Sweet", forState: .Normal)
    view.addSubview(btn1)

    let btn2: FlatButton = FlatButton()
    btn2.setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
    btn2.borderColor = MaterialColor.blue.accent3
    btn2.pulseColor = MaterialColor.blue.accent3
    btn2.borderWidth = .Border1
    btn2.setTitle("Good", forState: .Normal)
    view.addSubview(btn2)

    let btn3: FlatButton = FlatButton()
    btn3.setTitleColor(MaterialColor.blue.accent3, forState: .Normal)
    btn3.borderColor = MaterialColor.blue.accent3
    btn3.pulseColor = MaterialColor.blue.accent3
    btn3.borderWidth = .Border1
    btn3.setTitle("Nice", forState: .Normal)
    view.addSubview(btn3)

    // Initialize the menu and setup the configuration options.
    flatMenu = Menu(origin: CGPointMake(spacing, view.bounds.height - height - spacing))
    flatMenu.direction = .Down
    flatMenu.spacing = 8
    flatMenu.buttonSize = CGSizeMake(120, height)
    flatMenu.buttons = [btn1, btn2, btn3]
}

flatMenu是材料库中的Menu类型,是一个类,包含菜单中的每个按钮。“原产地”似乎控制了页面上的位置,但是由于Menu不是UIView子类,所以我不知道如何将它与自动输出一起使用。

代码语言:javascript
复制
public class Menu {
...
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-13 00:11:08

你的按钮在什么地方?尝试使用与按钮大小相同的尺寸来定位带有AutoLayout的超级视图,然后将菜单的来源设置为CGRectZero。

还要确保将superview的clipsToBounds设置为false (默认值)。而且,由于按钮超出了autolayout放置视图的范围,因此需要使用自定义的UIView子类来处理按钮上的操作,如下所示。

代码语言:javascript
复制
class MenuParentView: UIView {

  override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {

    //because the subviews will be outside the bounds of this view
    //we need to look at the subviews to see if we have a hit
    for subview in self.subviews {
        let pointForTargetView = subview.convertPoint(point, fromView: self)
        if CGRectContainsPoint(subview.bounds, pointForTargetView) {
            return subview.hitTest(pointForTargetView, withEvent: event)
        }
    }

    return super.hitTest(point, withEvent: event)
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35373363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档