是否有人知道停止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