如何在viewController中制作CAAnimation,它没有使用navigationController

时间:2016-03-30 12:42:34

标签: ios caanimation

在我的代码中,新的viewcontroller没有被推入导航控制器并被显示为小部件。

-(void) loadBlurWidgetsWithClass:(Class) widgetClass andXib:(NSString*) xibName options:(NSDictionary *)options completion:(void (^)(void))competionBlock
{

     [self unloadBlurWidgetsRemovingView:NO];

     self.blurViewController = [[widgetClass alloc] initWithNibName:xibName bundle:nil options:options];
     [self.navigationItem.leftBarButtonItem setEnabled:NO];
     [self.blurViewController.view setBounds:self.view.bounds];
     [self.view addSubview:self.blurViewController.view];
     [self.blurViewController.view removeFromSuperview];

     self.blurViewController.main = self;

     [self showBlurViewDynamic:[options[@"dynamic"] boolValue] WithCompletion:^{
     for(UIView* v in self.blurViewController.view.subviews)
     {
          [_blurView addSubview:v];
     }
     if (competionBlock) {
          competionBlock();
     }
}];

}

通过这个新类viewWillAppear和viewDidAppear没有被解雇。但是在课堂上我想使用动画,我必须在viewDidAppear中初始化。你有一个解决方案,我可以调用viewDidAppear或如何制作动画。提前谢谢。

1 个答案:

答案 0 :(得分:1)

你需要将self.blurViewController's视图添加为子视图而不是其子视图, 为了调用viewWillAppearviewDidAppear视图控制器视图应该在那里,但你正在做[self.blurViewController.view removeFromSuperview];此行删除了视图控制器视图,视图控制器中没有视图以便调用将/似乎出现方法。如果你想调用这些方法不要删除视图控制器的主视图,如果你不想要主视图控制器的视图,那么你可以将其背景颜色设置为clear或alpha设置为零或略高于零。

 self.blurViewController = [[widgetClass alloc] initWithNibName:xibName bundle:nil options:options];
 [self.navigationItem.leftBarButtonItem setEnabled:NO];
 [self.blurViewController.view setBounds:self.view.bounds];
 [self.view addSubview:self.blurViewController.view];
// [self.blurViewController.view removeFromSuperview]; 
 [self.blurViewController.view.alpha = 0.2f;
 //or
 //self.blurViewController.view.backgroundColor = [UIColor clearColor];
 [self showBlurViewDynamic:[options[@"dynamic"] boolValue] WithCompletion:^{
      [_blurView addSubview:self.blurViewController.view];
      if (competionBlock) {
      competionBlock();
 }}];