【问题标题】:Changing y position of view removes tap events更改视图的 y 位置会删除点击事件
【发布时间】:2019-07-18 06:28:07
【问题描述】:
  1. 我在屏幕外设置了一个 UICollectionView y 位置(将其设置为与底部安全区域对齐,并偏移 -154,因此它在屏幕外)。

  2. 当应用启动时,我使用一个按钮将整个根视图向上移动

    self.view.center.y -= 154

  3. 根视图和我的 UIView 都出现在预期位置,但无法点击 UICollectionView。新区域无法识别 UIEvent。

我向 UICollectionView 添加了一个手势,但它不起作用。只有根视图区域响应 UIEvent。

@IBAction func filmRollButton(_ sender: UIButton) {
    var toUp = true

    if self.toUp == true {
        self.view.center.y -= 154
    } else {
        self.view.center.y += 154
    }
    self.toUp = !self.toUp
}

// tap - UICollection View appear(y position change)
// tap again - UICollection view disappear

预期:

  1. 使用一些方法来启用 UICollectionView 点击事件。 (扩展根视区?因为只能点击根视区。)
  2. 其他简单的绘制效果,例如将 UICollectionView 高度设置为 0,然后点击按钮并将高度设置为 154。

【问题讨论】:

    标签: ios swift uicollectionview yaxis


    【解决方案1】:

    尝试使用 layoutIfNeeded() 来立即布局子视图。可能正在等待

     @IBAction func filmRollButton(_ sender: UIButton) {
      var toUp = true
    
      if self.toUp == true {
         self.view.center.y -= 154
         self.view.layoutIfNeeded()
       } else {
         self.view.layoutIfNeeded()
         self.view.center.y += 154
       }
         self.toUp = !self.toUp
    }
    
        // tap - UICollection View appear(y position change)
        // tap again - UICollection view disappear
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 2015-10-11
      相关资源
      最近更新 更多