Objective c 为什么我的UIViewController要加载两次?损失7
我正在用自定义动画演示我的自定义Objective c 为什么我的UIViewController要加载两次?损失7,objective-c,animation,ios7,presentmodalviewcontroller,uiviewanimationtransition,Objective C,Animation,Ios7,Presentmodalviewcontroller,Uiviewanimationtransition,我正在用自定义动画演示我的自定义UIViewController(称为“temp”)。使用以下命令调用UIVC: [temp setModalPresentationStyle:UIModalPresentationCustom]; temp.transitioningDelegate = self; [temp.view setHidden:YES]; [self presentViewController:temp animated:YES completion:nil]; 我的自定义动画
UIViewController
(称为“temp”)。使用以下命令调用UIVC:
[temp setModalPresentationStyle:UIModalPresentationCustom];
temp.transitioningDelegate = self;
[temp.view setHidden:YES];
[self presentViewController:temp animated:YES completion:nil];
我的自定义动画是从屏幕的右上角到左上角以模式显示视图。它被隐藏显示,因此用户看不到动画。在到达屏幕高度(768)位置后,它被设置为可见和动画(移动),从上到下呈现在中间。目标是从上到下呈现一个视图,并从上到下消除它(如电影场景)。此代码不起作用:
- (void)animateTransition:(id)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSLog(@" fromViewController %@ ",fromViewController);
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSLog(@" toViewController %@ ",toViewController);
UIView *containerView = [transitionContext containerView];
if (self.presenting)
{
// set starting rect for animation toViewController.view.frame = [self rectForDismissedState:transitionContext];
[containerView addSubview:toViewController.view];
[UIView animateWithDuration:0.5
animations:^{
toViewController.view.frame = CGRectMake(-self.customSize.width, self.yValue, self.customSize.width, self.customSize.height);
}
completion:^(BOOL finished)
{
//HERE IS THE PROBLEM!!!
[toViewController.view setHidden:NO];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
CGRect variable = [self rectForPresentedState:transitionContext];
CGRect fitToCurrentScreenResolution = CGRectMake(0, 0, variable.size.width, variable.size.height);
toViewController.view.frame = fitToCurrentScreenResolution;
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
}];
}];
}
else
{
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
fromViewController.view.frame = [self rectForDismissedState:transitionContext];
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
[fromViewController.view removeFromSuperview];
}
];
}
}
以下是解决方案:
- (void)animateTransition:(id)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
NSLog(@" fromViewController %@ ",fromViewController);
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSLog(@" toViewController %@ ",toViewController);
UIView *containerView = [transitionContext containerView];
if (self.presenting)
{
// set starting rect for animation toViewController.view.frame = [self rectForDismissedState:transitionContext];
[containerView addSubview:toViewController.view];
[UIView animateWithDuration:0.5
animations:^{
toViewController.view.frame = CGRectMake(-self.customSize.width, self.yValue, self.customSize.width, self.customSize.height);
}
];
[toViewController.view setHidden:NO];
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
CGRect variable = [self rectForPresentedState:transitionContext];
CGRect fitToCurrentScreenResolution = CGRectMake(0, 0, variable.size.width, variable.size.height);
toViewController.view.frame = fitToCurrentScreenResolution;
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
}];
}
else
{
[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
fromViewController.view.frame = [self rectForDismissedState:transitionContext];
}
completion:^(BOOL finished)
{
[transitionContext completeTransition:YES];
[fromViewController.view removeFromSuperview];
}
];
}
}
我的问题很简单。为什么我的UIVC要展示两次
- 我曾尝试将我的自定义UIVC设置为延迟加载的属性,但我的应用程序崩溃了,因为UIVC=nil无法以模式显示
- 我尝试过此解决方案,但不适用于我的问题:
- 我也是在没有帮助的情况下这样做的:
感谢您的建议/评论。iOS 8.0、Xcode 6.0.1、ARC启用 是的,你肯定是通过“链接动画”(见O.p.的评论)进入它 我在应用程序中看到了一个类似的问题,试图隐藏和显示各种UIViewController的UIStatusBar,例如,我有一个虚拟加载后屏幕UIViewController,它显示与加载屏幕相同的图像,但它有一些附加动画 我使用的是一个自定义转换,它具有一个UIViewController,通过从自身添加或删除视图并将“to”UIViewController控件分配给自身,处理从“from”UIViewController和“to”UIViewController的转换。诸如此类 在应用程序中。代表
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
我必须实例化“初始视图控制器”,然后用它初始化转换UIViewController。由于没有“到”UIViewController,因此在触发转换之前,转换UIViewController必须保留初始化时使用的UIViewController的初始UIView
这是利用,
self.window.rootViewController = self.transitionViewController;
[self.window makeKeyAndVisible];
在第一次转换之后,始终有两个UIView相互重叠。和两个UIViewController—一个作为转换期间分配的转换UIViewController的当前控件存在,另一个作为前一个UIViewController存在,直到转换完成
这是我试图用来显示/隐藏UIStatusBar的代码,必须在*-Info.plist文件中将“基于视图控制器的状态栏外观”设置为“是”
- (void)viewDidLoad
{
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
- (BOOL)prefersStatusBarHidden
{
return false;
}
无论何时,“return”值从默认值“false”更改为“true”
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
已触发、延迟、无延迟、有条件等。;UIViewController、“收件人”和“发件人”都已重新加载。起初这并不明显,但是在一个UIViewController中实现了NSURLSession之后,该UIViewController在-(void)ViewDidLoad中被触发;问题很清楚。该会话执行了两次,所涉及的图形内容也得到了更新
我用两种方法成功地解决了这个问题,但我保留了第二种方法
谢谢。希望这对别人有帮助。请对OP或我今后如何处理这一问题发表意见。嘿,刚刚登记!你有没有找到解决办法?我刚刚结束了与类似问题的4天斗争。您发布的代码是“…这是解决问题的解决方案”吗?是的,代码在iOS7中运行良好,但在iOS8中没有。当发生自定义转换时,像“不工作代码”示例这样的链接动画似乎会产生问题。我认为这是因为大多数人使用的自定义转换代码示例。在某个地方,景色有两次起伏。对两者都有效的解决方案是在viewDidLoad中添加SKView,因为它只加载一次。“这最终帮了我的忙。”香蕉开发者iDrioid,谢谢你这么快澄清!我很高兴听到你找到了一个工作,这将是很好的深入调查,并找出确切的罪犯。。。我将公布我的情况,也许其他人可以将两者联系在一起。。。