【问题标题】:IB Action is not getting called from Custom View未从自定义视图调用 IB 操作
【发布时间】:2019-02-06 10:56:16
【问题描述】:

当视图确实出现时,我正在显示一个视图,视图上有一个按钮没有被点击。动画工作得很好。

func checkNotificationPermission(){

        if #available(iOS 10.0, *) {

            UNUserNotificationCenter.current().getNotificationSettings { (settings) in
                if settings.authorizationStatus == .authorized{
                    print("ProfileVC permission granted for notification")
                }else{

                    DispatchQueue.main.sync {

                        self.productCollectionView.isUserInteractionEnabled = false
                        UIView.animate(withDuration: 1, delay: 3, options: [.transitionFlipFromTop, .allowUserInteraction], animations: {

                                self.notificationView.frame = CGRect(x: 16, y: (UIScreen.main.bounds.size.height - 180), width: (UIScreen.main.bounds.size.width - 32), height: 150)

                        }, completion: { (isCompleted) in

                            UIView.animate(withDuration: 1, delay: 10, options: [.transitionFlipFromTop, .allowUserInteraction], animations: {

                                    self.notificationView.frame = CGRect(x: 16, y: UIScreen.main.bounds.size.height, width: (UIScreen.main.bounds.size.width - 32), height: 150)

                            }, completion: { (isCompleted) in
                                self.productCollectionView.isUserInteractionEnabled = true
                            })
                        })
                    }
                    print("ProfileVC permission not granted for notification")
                }
            }
        }else{
            // Fallback on earlier versions
            if UIApplication.shared.isRegisteredForRemoteNotifications {
                print("ProfileVC APNS-YES")
            } else {
                print("ProfileVC APNS-NO")
            }
        }
    }

IBAction 有,连接也有。

@IBAction func setttingButtonPressed(_ sender: UIButton) {
    print("setting button pressed")

}

我检查了视图调试器,自定义视图显示集合视图的顶部,您可以在 customView 下看到。

【问题讨论】:

  • 您是否尝试在连接到按钮的函数中设置断点?断点被命中了吗?
  • @waldrumpus 我在未执行的 IB Action 方法中放置了简单的打印语句,我的意思是在控制台中看不到任何内容。您现在可以看到有问题的 IB Action 代码。
  • 您似乎已经正确测试了视图层次结构。但是您是否尝试过使用view.bringSubview(toFront:)确保按钮位于最顶端?
  • notificationView 是带有您的按钮 @IBAction func 的自定义类吗?或者它只是你的视图控制器的一个子视图,而按下的按钮功能在视图控制器中?
  • 显示您在哪个视图上调用此操作以及如何调用? @GaneshPawar

标签: ios swift view uibutton ibaction


【解决方案1】:

检查isUserInteractionEnabled 以获取您添加的视图。必须是true

您可以在视图调试器本身中调试此属性

【讨论】:

  • 我检查了属性检查器,isUserInteractionEnabled它被检查或设置为true
  • 您应该在运行时以Debug View Hierarchy 模式检查。如果有其他事情,这可能是唯一的原因。您还应该提供代码 VC 代码故事板和调试模式屏幕。而且我不明白这个反对投票的答案有什么问题。
猜你喜欢
  • 1970-01-01
  • 2012-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
  • 1970-01-01
相关资源
最近更新 更多