【问题标题】:How to show a pop up view exactly in the center of what is currently being displayed in a table view conntroller?如何在表格视图控制器中当前显示的内容的中心准确显示弹出视图?
【发布时间】:2021-11-19 20:35:10
【问题描述】:

我的应用程序有一个 SettingsVC,它包含一个 TableView,详细说明了我的应用程序的所有可用选项。我想在用户点击这些选项之一时显示一个弹出视图,以避免将用户带到另一个 VC。我目前已经在应用程序的其他部分实现了弹出视图,但是在尝试从 SettingsVC 呈现它时出现问题,似乎边界是针对 tableView 的整个大小而不是当前屏幕上的大小,所以如果我向下滚动,弹出窗口会一直向上出现......任何想法。这是我的弹出视图的设置方法。 animateIn() 方法是呈现弹出视图和模糊视图。

func setUpPickerView(){
        blurView.bounds = self.view.bounds
        pickerView.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width * 0.75, height: self.view.bounds.height * 0.45)
        pickerView.layer.cornerRadius = 15.0
        pickerView.layer.cornerRadius = 15.0
        animateIn(desiredView: blurView)
        animateIn(desiredView: pickerView)
        tableView.isUserInteractionEnabled = false
        blurView.alpha = 0.6
    }

【问题讨论】:

    标签: ios swift uitableview popup


    【解决方案1】:

    视图的bounds 是视图内部的坐标系。视图的frame 定义了视图在其父坐标系中出现的位置。您的代码只看到bounds,因此框架可能默认位于屏幕顶部。我怀疑你想要这样的东西:

    blurView.frame = self.view.bounds
    pickerView.frame = CGRect(
        x: (blurView.bounds.size.height - self.view.bounds.width * 0.75) / 2
        y: (blurView.bounds.size.width - self.view.bounds.height * 0.45) / 2
        width: self.view.bounds.width * 0.75
        height: self.view.bounds.height * 0.45)
    

    但是,您真正应该做的是设置blurViewpickerView,然后使用约束确定它们的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      相关资源
      最近更新 更多