如何实现覆盖按钮,这是浮在内容视图 [英] How to implement a overlay button which is floating over the content view
问题描述
在一些iPhone应用程序我看到了一个按钮这是<强>漂浮在内容视图,例如。在应用程序EyeEm本质上。当用户正在滚动内容,按钮保持它在哪里,仍然是一个交互元件。
浩我实现这个?
我的做法是:
- 创建与内容的图
- 放在一个按钮
- 但如何使按钮浮动?
编辑:
浮动似乎是默认行为。有趣的是 addSubview
和 insertSubview
放置按钮时......无一不是漂浮在内容具有相同的行为。
- (无效){addOverlayButton
*的UIButton = oButton [UIButton的buttonWithType:UIButtonTypeRoundedRect];
[oButton addTarget:自我
行动:@选择(:) amethod方法
forControlEvents:UIControlEventTouchDown];
[oButton的setTitle:@显示视图forState:UIControlStateNormal];
oButton.frame = CGRectMake(80.0,210.0,160.0,40.0);
[self.view addSubview:oButton];
//[self.view insertSubview:oButton aboveSubview:_scrollView]; //同样的结果addSubview。
//这两种解决方案让按钮浮动过的内容。
}
添加一个子视图到你的窗口的内容视图与 insertSubview:aboveSubview:
方法与你的按钮和滚动型为参数,但要小心:如果两个兄弟视图都具有透明性,由此产生的绘画行为是不确定的。
in some iPhone apps i saw a button which was floating over the content view, eg. in the app EyeEm. When the user is scrolling the content, the button remains where it is and is still an interaction element.
Ho do I implement this?
My approach would be:
- Create a view with content
- Put a button on it
- But how to make the button floating?
edit:
The floating seems to be the default behavior. Interestingly addSubview
and insertSubview
have the same behavior when placing the button... both are floating over the content.
- (void)addOverlayButton {
UIButton *oButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[oButton addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[oButton setTitle:@"Show View" forState:UIControlStateNormal];
oButton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:oButton];
//[self.view insertSubview:oButton aboveSubview:_scrollView]; // same result as addSubview.
// Both solutions let the button float over the content.
}
Add a subview to your window's content view with insertSubview:aboveSubview:
method with your button and scrollview as arguments, but be careful: if two sibling views both have transparency, the resulting drawing behaviour is undefined.
这篇关于如何实现覆盖按钮,这是浮在内容视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!