Swift-除非长时间点按,否则按钮的操作不会被触发

问题描述

我在Sign in with Apple中添加了一个UIScrollView按钮,就像苹果文档中所建议的那样;

let signInWithAppleButton = ASAuthorizationAppleIDButton(type: .default,style: .white)
            
signInWithAppleButton.addTarget(self,action: #selector(loginWithApple(_:)),for: .touchUpInside)
signInWithAppleButton.cornerRadius = 12
            
scrollView.addSubview(signInWithAppleButton)

问题是,该按钮仅对非常长的按下响应,而不是简单的点击。我试过将其放在UIScrollView之外,并且在其中起作用!

这是我的UIScrollView和按钮的设置;

fileprivate func setupScrollViewConstraints() {
    scrollView.translatesAutoresizingMaskIntoConstraints = false
    
    NSLayoutConstraint.activate([
        scrollView.topAnchor.constraint(equalTo: self.view.topAnchor),scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
    ])
}

func setupSignInWithAppleButton() -> UIControl? {
    if #available(iOS 13.0,*) {
        let signInWithAppleButton = ASAuthorizationAppleIDButton(type: .default,style: .white)
        
        signInWithAppleButton.addTarget(self,for: .touchUpInside)
        signInWithAppleButton.cornerRadius = 12
        
        scrollView.addSubview(signInWithAppleButton)
        
        signInWithAppleButton.translatesAutoresizingMaskIntoConstraints = false
        
        NSLayoutConstraint.activate([
            signInWithAppleButton.topAnchor.constraint(equalTo: accountLabel.bottomAnchor,constant: 8),signInWithAppleButton.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),signInWithAppleButton.widthAnchor.constraint(equalToConstant: 210),signInWithAppleButton.heightAnchor.constraint(equalToConstant: 45)
        ])
        
        return signInWithAppleButton
    }
    
    return nil
}

任何想法都在破坏它吗?

编辑; 这是我的处理程序;

@objc private func loginWithApple(_ sender: Any) {
    let appleIDProvider = ASAuthorizationAppleIDProvider()
        
    let request = appleIDProvider.createRequest()
    request.requestedScopes = [.fullName,.email]
        
    let authorizationController = ASAuthorizationController(authorizationRequests: [request])
        
    authorizationController.delegate = self
    authorizationController.presentationContextProvider = self
    authorizationController.performRequests()
}

我已经在其中放置了一个断点,但是只有长按按钮才能激活它!只是提醒一下,如果将按钮放在控制器的视图内,该按钮将按预期工作!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)