UIViewControllerAnimated(true, completion: {}) を使用して UIViewController を閉じようとしていますが、実行しようとすると EXC_BAD_ACCESS が発生します。(つまり、10 回に 1 回は機能します)。
カスタムの transitionDelegate を使用しましたが、それを設定していない場合は機能します。
ListTransitionDelegate はアニメーターと presentationController を返します。
プレゼンテーションコントローラーは次のようになります
init(presentingViewController: UIViewController!, presentedViewController: UIViewController!, controllerStyle: SideControllerStyle, shortest: CGFloat) {
self.controllerStyle = controllerStyle
self.shortest = shortest
super.init(presentingViewController: presentingViewController, presentedViewController: presentedViewController)
self.dimmingView.backgroundColor = UIColor.blackColor()
var tapGesture = UITapGestureRecognizer(target: self, action: Selector("closePresented"))
dimmingView.addGestureRecognizer(tapGesture)
}
override func adaptivePresentationStyle() -> UIModalPresentationStyle
{
return UIModalPresentationStyle.OverFullScreen
}
override func shouldPresentInFullscreen() -> Bool
{
return true
}
override func presentationTransitionWillBegin() {
var containerView = self.containerView
self.dimmingView.frame = self.containerView.bounds
containerView.insertSubview(self.dimmingView, atIndex:0)
presentedViewController.transitionCoordinator().animateAlongsideTransition({context in
self.dimmingView.alpha = 0.5
}, completion:nil)
}
override func presentationTransitionDidEnd(completed: Bool)
{
if !completed {
self.dimmingView.removeFromSuperview()
}
}
override func dismissalTransitionDidEnd(completed: Bool)
{
self.dimmingView.removeFromSuperview()
}
override func dismissalTransitionWillBegin() {
presentedViewController.transitionCoordinator().animateAlongsideTransition({context in
self.dimmingView.alpha = 0
}, completion: nil)
}
func closePresented() {
var presenting = self.presentingViewController
presentedViewController.dismissViewControllerAnimated(true, completion: nil)
}
override func sizeForChildContentContainer(container: UIContentContainer!, withParentContainerSize parentSize: CGSize) -> CGSize {
var size : CGSize
switch self.controllerStyle {
case .Left, .Right:
size = CGSizeMake(self.shortest, parentSize.height)
case .Bottom, .Top:
size = CGSizeMake(parentSize.width, self.shortest)
default:
size = CGSizeMake(parentSize.width, parentSize.height)
}
return size
}
override func frameOfPresentedViewInContainerView() -> CGRect {
var frame : CGRect
var size = sizeForChildContentContainer(nil, withParentContainerSize: containerView.bounds.size)
switch self.controllerStyle {
case .Left:
frame = CGRectMake(containerView.bounds.size.width - size.width, 0, size.width, size.height)
case .Right:
frame = CGRectMake(0, 0, size.width, size.height)
case .Bottom:
frame = CGRectMake(0, containerView.bounds.size.height - size.height, size.width, size.height)
case .Top:
frame = CGRectMake(0, 0, size.width, size.height)
default:
frame = CGRectMake(0, 0, size.width, size.height)
}
return frame
}