Gly*_*ard 3 xcode objective-c ios swift
我正在按照苹果创建自定义视图控制器的WWDC发布的"查看内部视图控制器"教程(视频:https://developer.apple.com/videos/wwdc/2014/,示例代码如下:https:/ /developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html).我一直在复制他们的目标-C并逐行将其翻译成Swift,我几乎让它工作,除了用手势点击隐藏叠加的viewController.
我打电话的时候:
func dimmingViewTapped(recognizer: UIGestureRecognizer) {
self.presentingViewController.dismissViewControllerAnimated(true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:如果动画字段设置为true,则线程1:EXC_BAD_ACCESS(代码= 1,地址= 0xc).如果它被设置为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
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有关于此的一些问题,但在阅读之后,我仍然感到难过,正在寻求帮助.
小智 9
确保您的过渡代表得到强有力的支持.将其设置为控制器上的强属性.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SearchDetailsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"SearchStoryboardID"];
viewController.delegate = self;
SearchDetailsViewControllerTransitioningDelegate *transitioningDelegate = [[SearchDetailsViewControllerTransitioningDelegate alloc] init];
**self.detailsTransitioningDelegate** = transitioningDelegate;
viewController.transitioningDelegate = (id <UIViewControllerTransitioningDelegate>)self.detailsTransitioningDelegate;
[self presentViewController:viewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1827 次 |
| 最近记录: |