Har*_*iks 6 android ios floating-action-button react-native
在较高级别的组件中使用绝对定位的按钮将在正常使用情况下发挥作用,但是当呈现模式/动作表/选择器等时,该按钮将不再位于顶部。
免责声明:这样做几乎肯定会导致您的应用被应用商店拒绝,因此您应该确保它仅在Beta和内部版本中显示。如果您需要Apple接受它,我建议您通过React Native实现UIActionSheets和UIAlerts。有很多很好的库可以模拟模态。
您需要在本机端执行此操作。您可以将以下代码添加到您的AppDelegate中:
var debugWindow: UIWindow?
@objc func pressButton(_ sender: UIButton) {
print("Do debugging here")
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let screenSize = UIScreen.main.bounds
let buttonController = UIViewController()
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
button.setTitle("+", for: .normal)
button.backgroundColor = UIColor.blue
button.addTarget(self, action: #selector(pressButton(_:)), for: .touchUpInside)
button.layer.cornerRadius = 25
button.layer.masksToBounds = true
buttonController.view = button
debugWindow = UIWindow.init(frame: CGRect(x: screenSize.width - 100, y: screenSize.height - 100, width: 50, height: 50))
debugWindow!.rootViewController = buttonController
debugWindow!.windowLevel = UIWindow.Level.alert + 1000;
debugWindow!.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
346 次 |
| 最近记录: |