
func displaySignUpPendingalert() -> UIAlertController { //Create the UIAlertController let pending = UIAlertController(Title: "Creating New User",message: nil,preferredStyle: .Alert) //Create the activity indicator to display in it. let indicator = UIActivityIndicatorVIEw(frame: CGRectMake(pending.vIEw.frame.wIDth / 2.0,pending.vIEw.frame.height / 2.0,20.0,20.0)) indicator.center = CGPointMake(pending.vIEw.frame.wIDth / 2.0,pending.vIEw.frame.height / 2.0) //Add the activity indicator to the alert's vIEw pending.vIEw.addSubvIEw(indicator) //Start animating indicator.startAnimating() self.presentVIEwController(pending,animated: true,completion: nil) return pending } 但是,活动指示器不会显示在视图的中心,实际上它显示在屏幕的右下方,远离视图.这是什么原因?
编辑:我明白,我可以硬编码为指标的位置,但我希望警报工作在多个设备与多个屏幕尺寸和方向.
解决方法 创建视图时,请确保设置frame属性.func displaySignUpPendingalert() -> UIAlertController { //create an alert controller let pending = UIAlertController(Title: "Creating New User",preferredStyle: .Alert) //create an activity indicator let indicator = UIActivityIndicatorVIEw(frame: pending.vIEw.bounds) indicator.autoresizingMask = [.FlexibleWIDth,.FlexibleHeight] //add the activity indicator as a subvIEw of the alert controller's vIEw pending.vIEw.addSubvIEw(indicator) indicator.userInteractionEnabled = false // required otherwise if there buttons in the UIAlertController you will not be able to press them indicator.startAnimating() self.presentVIEwController(pending,completion: nil) return pending} 到@ 62Shark:
let pending = UIAlertController(Title: "Creating New User",preferredStyle: .Alert)let indicator = UIActivityIndicatorVIEw()indicator.setTranslatesautoresizingMaskIntoConstraints(false)pending.vIEw.addSubvIEw(indicator)let vIEws = ["pending" : pending.vIEw,"indicator" : indicator]var constraints = NSLayoutConstraint.constraintsWithVisualFormat("V:[indicator]-(-50)-|",options: nil,metrics: nil,vIEws: vIEws)constraints += NSLayoutConstraint.constraintsWithVisualFormat("H:|[indicator]|",vIEws: vIEws)pending.vIEw.addConstraints(constraints)indicator.userInteractionEnabled = falseindicator.startAnimating()self.presentVIEwController(pending,completion: nil) 总结 以上是内存溢出为你收集整理的ios – 如何在UIAlertController的中心显示活动指示器?全部内容,希望文章能够帮你解决ios – 如何在UIAlertController的中心显示活动指示器?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)