是否有人知道停止UIActivityIndicatorView(AI)/删除已添加到UIPageViewController的UIView的问题?Swift UIPageViewController&UIActivityIndicatorView
我展示AI使用:
override func viewWillLayoutSubviews() {
actInd.frame = CGRectMake(0,0, 80, 80)
actInd.center.x = self.view.center.x
actInd.center.y = self.view.center.y - 40
actInd.hidesWhenStopped = true
actInd.layer.cornerRadius = 5
actInd.alpha = 0.5
actInd.backgroundColor = UIColor.blackColor()
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
self.view.addSubview(actInd)
actInd.startAnimating()
// This next line prints out the details of each subview on the page for testing purposes
listSubviews(self.view)
我也是,用于测试目的,添加一个空的UIView到视图中使用:
aView.frame = CGRectMake(0, 0, 200, 200)
aView.backgroundColor = UIColor.blueColor()
self.view.addSubview(aView)
}
然后,我把我的Parse.com查询当数据准备就绪时,使用委托来通知UIPageViewController(例如这个视图)。这工作正常,我测试了数据正确返回,并且预期的方法正在被调用。
在这种方法我试图阻止UIActivityViewController &试图隐藏aView:
self.actInd.stopAnimating()
aView.removeFromSuperView()
这没有工作,所以我尝试:
self.actInd.removeFromSuperView()
这也不能工作。所以,我然后试图通过子视图上的当前视图,以搜寻使用:
func populateBoards(boards: [Board]) {
println(self.actInd) // PRINT LINE 1
var subviews = self.view.subviews
for v in subviews {
if v.isKindOfClass(UIActivityIndicatorView) {
println("YES, it is an activity view indicator \(v)") // PRINT LINE 2
v.stopAnimating()
v.removeFromSuperview()
}
}
self.boards = boards
println("Populated Boards!") // PRINT LINE 3
}
PRINT LINE 1个输出:>
PRINT LINE 2个输出:YES,它是一种活动视图指示器>
打印行3输出:“填充板!”
编辑:
的UIPageViewController是建立与下面的代码(如果它帮助):
func setupUIPageView() {
self.pageViewController = UIPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)
self.pageViewController.delegate = self
self.pageViewController.dataSource = self
var startVC = self.viewControllerAtIndex(0) as ViewController
var viewControllers:[ViewController] = [startVC]
self.pageViewController.setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
self.pageViewController.view.alpha = 0.0
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}
帮助!感谢所有提前:D
完美,那工作表示感谢。我没有意识到这甚至是可能的:D – bwash70
您可能对此课程感兴趣:https://github.com/goktugyil/CozyLoadingActivity – Esqarrouth