jer*_*rik 5 xcode overlay objective-c button floating
在一些iPhone应用程序我看到了一个按钮,这是漂浮在内容视图,例如.在应用程序EyeEm.当用户滚动内容时,按钮保持原样并且仍然是交互元素.
我可以实现这个吗?
我的方法是:
编辑:
浮动似乎是默认行为.有趣的是addSubview
,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.
}
Run Code Online (Sandbox Code Playgroud)
insertSubview:aboveSubview:
使用以按钮和滚动视图作为参数的方法将子视图添加到窗口的内容视图,但要小心:如果两个同级视图都具有透明度,则生成的绘图行为是未定义的。