ios - 从第二个 View 返回到一个 View 时,UIButton 不可单击

标签 ios swift uibutton

我有一个应用程序。我假设其中两个观点有问题。第一个 View 有三个按钮,一个放在另一个下面。单击三个中的任何一个都会将我们带到具有 3 个 tableview 单元格的第二个 View 。

问题是,如果我们转到第二个 View 并返回到第一个 View ,则第一个 View 中的按钮不可点击。我附上两个 View 的屏幕。

View 1:有 3 个按钮。 View 1: Three buttons

View 2:这些是 TableView 单元格。 View 2: Three table view cells

注意:表格 View 单元格是可点击的。我们按下关闭按钮返回到第一个 View 。在第二个 View 的左上角。

**问题简而言之:如果我们转到 View 2,单击“X”关闭按钮, View 1 中的三个按钮,即 fb、G+ 和 Email 不可单击。 **

这是第一个 View 中三个按钮的代码。

@IBAction func firstBtnAction(_ sender: Any) {
    let bounds = self.firstBtn.bounds
    UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [], animations: {
        self.firstBtn.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 20, height: bounds.size.height)
        self.firstBtn.isEnabled = false
    }, completion: nil)

    goaltype = "Conversion"

    UserGoal()

}

@IBAction func secondBtnAction(_ sender: Any) {
    let boundss = self.secondBtn.bounds
    UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [], animations: {
        self.secondBtn.bounds = CGRect(x: boundss.origin.x - 20, y: boundss.origin.y, width: boundss.size.width + 20, height: boundss.size.height)
        self.secondBtn.isEnabled = false
    }, completion: nil)

    goaltype = "Engagement"

    UserGoal()

}

@IBAction func thirdBtnAction(_ sender: Any) {
    let bounds3 = self.thirdBtn.bounds
    UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [], animations: {
        self.thirdBtn.bounds = CGRect(x: bounds3.origin.x - 20, y: bounds3.origin.y, width: bounds3.size.width + 20, height: bounds3.size.height)
        self.thirdBtn.isEnabled = false
    }, completion: nil)


    goaltype = "Storytelling"
    UserGoal()

}

第二个 View 表格 View 单元格有一个小动画。

编辑 1:当我尝试添加 isEnabled = true 时,按钮是可点击的。但是,由于动画,它会在每次点击时不断扩展。看图:

Expanded pic

如何使按钮可点击?

最佳答案

您正在为所有按钮设置 isEnabled = false。返回第一个 View 时启用它

self.firstBtn.isEnabled = true
self.secondBtn.isEnabled = true
self.thirdBtn.isEnabled = true

对于仅在动画时禁用按钮,在完成 block 中启用它

UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [], animations: {
            self.thirdBtn.bounds = CGRect(x: bounds3.origin.x - 20, y: bounds3.origin.y, width: bounds3.size.width + 20, height: bounds3.size.height)
            self.thirdBtn.isEnabled = false
        }) { (_ isCompleted) in
            self.thirdBtn.isEnabled = true
        }

类似地为 firstBtnsecondBtn 动画做这件事

关于ios - 从第二个 View 返回到一个 View 时,UIButton 不可单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44838807/

相关文章:

ios - 在 iOS 上使用 google api 获取 json 数据时遇到问题

ios - 更新到 Xcode 9 后 UITableView 中的布局问题

ios - 唯一整数值

json - Swift - 读取 JSON 文件

ios - 当它进入 parent 可见区域时,将触摸事件添加到 uibutton

iphone - 如何仅从右向左扩展 UIButton 宽度

ios - [UIButton copyWithZone :]: unrecognized selector sent to instance

ios - SpriteKit 创建迷宫

ios - 在选定的行快速推送 segue 3

ios - 在随机ViewController中设置值(随机segue)