我正在關注由WWDC發佈的WWDC發佈的教程「視圖控制器內部」,以創建自定義視圖控制器(視頻位於:https://developer.apple.com/videos/wwdc/2014/和示例代碼:https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html)。我一直在複製它們的Objective-C並將它翻譯成Swift,並且我幾乎可以正常工作,除了用一個手勢點擊隱藏overlay viewController。DismissViewControllerAnimated EXC_Bad_ACCESS on true
當我打電話:
func dimmingViewTapped(recognizer: UIGestureRecognizer) {
self.presentingViewController.dismissViewControllerAnimated(true, completion: nil)
}
我得到一個錯誤:線程1:EXC_BAD_ACCESS(代碼= 1,地址= 0xC的),如果動畫字段設置爲true。如果它設置爲false,那麼所有的工作都很完美,並且在沒有動畫的情況下消失)。另一個奇怪的是,它有時會設置爲true時工作。也許每15次嘗試一次動畫就會完成,我不會收到錯誤。
我遵循與示例代碼中定義的完全相同的結構,其中包含處理創建呈現控制器對象以及動畫的轉換委託。
class OverlayTransitioningDelegate : NSObject, UIViewControllerTransitioningDelegate {
func presentationControllerForPresentedViewController(presented: UIViewController,
presentingViewController presenting: UIViewController,
sourceViewController source: UIViewController) -> UIPresentationController {
return OverlayPresentationController(presentedViewController: presented,
presentingViewController: presenting)
}
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning()
animationController.isPresentation = true
return animationController
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning()
animationController.isPresentation = false
return animationController
}
}
我知道已經有幾個問題在那裏對此但是他們閱讀後,我還是住了,正在尋找幫助。