objective-c - 如何实现 float 在内容 View 上的叠加按钮

标签 objective-c xcode button overlay floating

在某些 iPhone 应用程序中,我看到一个按钮 float 在内容 View 上,例如。在应用程序 EyeEm 中。当用户滚动内容时,按钮保持在原处并且​​仍然是一个交互元素。 Overlay Button which is floating over the content view

我该如何实现?

我的方法是:

  • 创建包含内容的 View
  • 在上面放一个按钮
  • 但是如何让按钮 float 呢?

编辑:

float 似乎是默认行为。有趣的是,addSubviewinsertSubview 在放置按钮时具有相同的行为...两者都 float 在内容上。

- (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: 方法将 subview 添加到您的窗口的内容 View 中,并将您的按钮和 ScrollView 作为参数,但要小心:如果两个同级 View 都具有透明度,则生成的绘制行为是未定义的.

关于objective-c - 如何实现 float 在内容 View 上的叠加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17040776/

相关文章:

ios - 在 MKMapView 中覆盖城市、地区等

swift - 获取具有多个部分的表中一行的索引路径

javascript - 创建多个弹出按钮

angular - 以 Angular 4 显示一个 div 并隐藏另一个 div

ios - 如何在 iOS 上获取符号地址?

ios - 为什么按钮宽度在 UINavigationbar 中有冲突?

html - 在Xcode上编译后,Crow C++框架HTML页面为空

ios - 如何检查按钮的文本是否包含数组元素?

iphone - 使用 Objective C 从 RGB 转换为 HSL

iphone - 如何修复xcode警告UIActivityIndi​​catorView的xcode 4中的“表达式结果未使用”