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.![Overlay Button which is floating over the content view](https://i.stack.imgur.com/UjaKM.png)
我如何实现这个?
我的方法是:
- 创建包含内容的视图
- 在上面放一个按钮
- 但是如何让按钮浮动呢?
edit:
浮动似乎是默认行为。有趣的是addSubview
and insertSubview
放置按钮时具有相同的行为...两者都浮动在内容上。
- (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.
}
将子视图添加到窗口的内容视图中insertSubview:aboveSubview:
方法以按钮和滚动视图作为参数,但要小心:如果两个同级视图都具有透明度,则生成的绘图行为是未定义的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)