0

嗨,我是 swift 新手,目前我正在从事一个项目,该项目之前在 swift 2.3 中为 iPad 和 iPhone 完成。我的要求是使用织物数字框架来使用手机号码进行注册。我按照文档中的内容进行了所有操作,但是由于某种原因,我的屏幕(UIViewController)中没有出现粉红色的“使用电话号码登录”按钮。代码如下。

import Alamofire
import SwiftyJSON
import DigitsKit


class ViewController: UIViewController, UITextFieldDelegate {

    var  phoneNum : String?
    let movement: CGFloat = 20.0
    var phoneHeight: CGFloat = 0.0
    var appURLs = AppURLs.sharedInstance
    var loadingView: UIView!
    var Id: Int!
    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var activity: UIActivityIndicatorView!
    @IBOutlet weak var password: UITextField!
    @IBAction func signUpButton(sender: AnyObject) {
        let storyboard = switchStoryboards()
        let vc = storyboard.instantiateViewControllerWithIdentifier("SignUpViewController")
        self.presentViewController(vc, animated: false, completion: nil)
    }

 override func viewDidLoad() {
        super.viewDidLoad()


        configureLoadingView()
        phoneHeight = self.view.frame.height
        UIApplication.sharedApplication().statusBarHidden = true
        self.username.delegate = self
        self.password.delegate = self
        self.slideMenuController()?.removeLeftGestures()
        let usernameImageView = UIImageView()
        if isIphone() {
            usernameImageView.frame = CGRect(x: 0, y: 0, width: 36, height: 20)
        } else {
            usernameImageView.frame = CGRect(x: 0, y: 0, width: 54, height: 30)
        }
        usernameImageView.image = UIImage(named: "Username")
        view.addSubview(usernameImageView)
        username.leftView = usernameImageView
        username.leftViewMode = UITextFieldViewMode.Always

        let passwordImageView = UIImageView()
        if isIphone() {
            passwordImageView.frame = CGRect(x: 0, y: 0, width: 36, height: 20)
        } else {
            passwordImageView.frame = CGRect(x: 0, y: 0, width: 54, height: 30)
        }
        passwordImageView.image = UIImage(named: "Password")
        view.addSubview(passwordImageView)
        password.leftView = passwordImageView
        password.leftViewMode = UITextFieldViewMode.Always

        print("Login view did load loaded")

        let authButton = DGTAuthenticateButton(authenticationCompletion: { (session, error) in
            if (session != nil) {
                // TODO: associate the session userID with your user model
                let message = "Phone number: \(session!.phoneNumber)"
                let alertController = UIAlertController(title: "You are logged in!", message: message, preferredStyle: .Alert)
                alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: .None))
                self.presentViewController(alertController, animated: true, completion: .None)
            } else {
                NSLog("Authentication error: %@", error!.localizedDescription)
            }
        })
        authButton?.center = self.view.center
        self.view.addSubview(authButton!)


    }

    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
    }

    func configureLoadingView() {
        loadingView = UIView(frame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height))
    }


    func loginAlerts(messages: String) {
        self.activity.stopAnimating()
        SwiftSpinner.show("Sign in Failed!", animated: false).addTapHandler({
            SwiftSpinner.hide()
            }, subtitle: messages)
    }
    func switchStoryboards() -> UIStoryboard {
        switch UIDevice.currentDevice().userInterfaceIdiom {
        case .Phone:
            // It's an iPhone
            return UIStoryboard(name: "Main", bundle: nil)
        case .Pad:
            return UIStoryboard(name: "StoryboardiPad", bundle: nil)
            // It's an iPad
        case .Unspecified:
            return UIStoryboard(name: "Main", bundle: nil)
            // Uh, oh! What could it be?
        default:
            return UIStoryboard(name: "Main", bundle: nil)
        }
    }

    func isIphone() -> Bool {
        switch UIDevice.currentDevice().userInterfaceIdiom {
        case .Phone:
            // It's an iPhone
            return true
        case .Pad:
            return false
            // It's an iPad
        case .Unspecified:
            return true
            // Uh, oh! What could it be?
        default:
            return true
        }
    }
}
4

1 回答 1

0

好的,在这种情况下,您所要做的就是在相关 UI 中创建一个自定义按钮,然后一切正常

于 2016-12-06T11:26:17.387 回答