ios - 在呈现之前添加 View Controller View

标签 ios modalviewcontroller

下面是我的代码..

TestTemp1ViewController *temp=[[TestTemp1ViewController alloc]init]; 
[self.view addSubview:temp.view];
[self presentModalViewController:temp animated:FALSE];

此代码在 iOS 5.0 中运行良好,但在 iOS 6.0 中崩溃。

Crash report: [UIViewController loadViewIfRequired]-- bad excess 

我不明白为什么这在 iOS 6.0 中不起作用。伙计们,我知道这不是好方法,但我想做的是用增长和收缩动画呈现 View Controller 。如果我在展示后执行此操作,那么我将获得 View Controller 的白色背景。

下面是我的代码...

-(void)animateGrowAndShrink:(ViewController *)controller1 {
    //self.view.userInteractionEnabled=NO;
    [self.view addSubview:controller1.view];
    [self presentModalViewController:self.controller animated:FALSE];
    if (dayTimeLineIsShown) {
        //shrink dayTimeLineIsShown=FALSE;
        [UIView beginAnimations:@"animationShrink" context:NULL];
        [UIView setAnimationDuration:.61f];
        controller1.view.transform=CGAffineTransformMakeScale(.01f,.01f);
    } else {
        //expand dayTimeLineIsShown=TRUE;
        controller1.view.transform=CGAffineTransformMakeScale(0.01,0.01);
        [UIView beginAnimations:@"animationExpand" context:NULL];
        [UIView setAnimationDuration:.60f];
        timeLine.view.transform=CGAffineTransformMakeScale(1, 1);
    }
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];     
    [UIView commitAnimations];
}

-(void)animationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
    self.view.userInteractionEnabled=YES;
   if ([animationID isEqualToString:@"animationExpand"]) {
        [self presentModalViewController:self.controller1 animated:FALSE];
    } else {
        self.controller.view.hidden=true;
    }
}.

如果我删除它,那么我正在执行此操作的 Controller 也会以模态方式呈现,然后它可以在 ios 6 中工作。实现缩放和缩小的任何其他想法。

最佳答案

-presentModalViewController-addSubview 完全不同,它们不应该一起使用。请参阅:When should I use the addSubview method of a view controller?

我认为删除第二行第三行会消除错误。

关于ios - 在呈现之前添加 View Controller View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14603318/

相关文章:

iphone - 如何创建从屏幕顶部推送的 UINavigationController?

ios - 在 initWithCoder : what are the keys in the NSCoder (a UINibDecoder)?(用于 UIImageView)

ios - 运行时的 Swift UITableViewCell 动态单元格高度

ios - 我可以模态呈现作为导航 Controller 一部分的 View Controller 吗?

swift 关闭模态并推送到新的 VC

ios - 类数组对象值在json序列化后总是返回nil

ios - 使用 XCUI 进行 UI 测试

ios - 在 iOS 中实现新的 "Card"样式模态视图的真实名称和方法是什么?

react-native - 如何在 react-native 中将 expo-blur 添加到模态中

iOS - 半透明模态视图 Controller