我在我的应用中需要一个show activityindicator,但我无法看到它。我有我的viewutils(类型为viewcontrollerultis),我用这种方式调用它:viewUtils.showActivityIndicator(self.view)。我不知道为什么会这样。
let viewUtils = ViewControllerUtils()
@IBAction func login(sender: AnyObject) {
viewUtils.showActivityIndicator(self.view)
username = userField.text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
password = passwordTextField.text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
if (self.username.isEmpty || self.password.isEmpty){
self.showAlert("Asegurese de ingresar un usuario y contraseña!")
}else{
var user = user_function()
if user.user_valid(username,password: password){
}else{
self.showAlert("Usuario Invalido")
}
}
viewUtils.hideActivityIndicator(self.view)
}
这是我的showactivityindicator:
func showActivityIndicator(uiView: UIView) {
container.frame = uiView.frame
container.center = uiView.center
container.backgroundColor = UIColorFromHex(0xffffff, alpha: 0.3)
loadingView.frame = CGRectMake(0, 0, 80, 80)
loadingView.center = uiView.center
loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.7)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.center = CGPointMake(loadingView.frame.size.width / 2, loadingView.frame.size.height / 2);
loadingView.addSubview(activityIndicator)
container.addSubview(loadingView)
uiView.addSubview(container)
activityIndicator.startAnimating()
}