こんにちは、私はswiftを初めて使用し、現在、iPadとiPhoneの両方でswift 2.3で以前に行われたプロジェクトに取り組んでいます。私の要件は、モバイル番号を使用してサインアップするためにファブリック数字フレームワークを使用することです.ドキュメントにあるようにすべてを行いましたが、ピンク色の「電話番号でログイン」ボタンが何らかの理由で私の画面(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
}
}
}