我是iOS开发中的新手,最近在iOS 9中通过自定义转换遇到了这个问题。
我有一个符合UIViewControllerTransitioningDelegate
协议的对象并实现了animationControllerForDismissedController
,类似于:
@implementation MyCustomizedTransitioningDelegate
#pragma mark - UIViewControllerTransitioningDelegate
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
MyCustomizedTransitionAnimator *animator = [[MyCustomizedTransitionAnimator alloc] init];
animator.presenting = NO;
return animator;
}
@end
触发模态转换的过程类似于:
@implementation MyViewController
#pragma mark - Initializers
+ (MyCustomizedTransitioningDelegate *)modalTransitioningDelegateSingletonInstance;
{
static MyCustomizedTransitioningDelegate *delegateInst = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
delegateInst = [[MyCustomizedTransitioningDelegate alloc] init];
});
return delegateInst;
}
#pragma mark - UIViewController
- (void)dismissViewControllerAnimated:(BOOL)animated completion:(void (^)(void))completion;
{
[self prepareForDismissViewControllerAnimated:animated completion:&completion];
[super dismissViewControllerAnimated:animated completion:completion];
}
- (void)prepareForDismissViewControllerAnimated:(BOOL)animated completion:(dispatch_block_t *)completion;
{
self.presentedViewController.modalPresentationStyle = UIModalPresentationCustom;
self.presentedViewController.transitioningDelegate = [[self class] modalTransitioningDelegateSingletonInstance];
}
@end
由于未调用animationControllerForDismissedController
方法,因此未创建MyCustomizedTransitionAnimator
,导致其animateTransition
未被调用,这会导致我的应用中出现意外问题。 (抱歉我的英语不好......)
我还附上了iOS8和iOS的堆栈跟踪截图。 iOS9。
在iOS 8中,在下面的堆栈跟踪之后调用animationControllerForDismissedController
。
但是在iOS9中,transitionDidFinish
会以某种方式提前调用,我猜可能会阻止调用animationControllerForDismissedController
?
我想知道这是不是iOS 9的bug。任何解释或解决方案将不胜感激!
答案 0 :(得分:9)
我遇到了同样的问题。
我希望这会对某人有所帮助。
为我修复的是将使用UIViewControllerTransitioningDelegate
协议作为变量实例的对象与其保持密切关系。
我认为因为在第一次呈现视图后它被解雇了。
答案 1 :(得分:4)
我有同样的问题。
原来我需要在包含触发按钮的navigationController
的{{1}}上设置委托。
这个旧代码不起作用:
UIViewController
我将第一行更改为:
UIViewController *dvc = [self sourceViewController];
TransitionDelegate *transitionDelegate = [TransitionDelegate new];
dvc.modalPresentationStyle = UIModalPresentationCustom;
dvc.transitioningDelegate = transitionDelegate;
[dvc dismissViewControllerAnimated:YES completion:nil];
并且有效。
希望这有帮助。
答案 2 :(得分:0)
您需要说出类似的内容:
protected void onPostExecute(String result) {
super.onPostExecute(result);
JSONObject json =new JSONObject(result);
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// your code here...
}
}
或者,如果您正在使用segues,请在prepareForSegue中说出如下内容:
MyDestinationViewController *viewController = [[MyDestinationViewController alloc] init];
MyCustomizedTransitioningDelegate *transitioningDelegate = [[MyCustomizedTransitioningDelegate alloc]init];
viewController.transitioningDelegate = transitioningDelegate;
viewController.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController: viewController animated:YES completion:nil];