如何在子视图控制器的视图实际出现时启动动画?

时间:2014-12-24 16:46:17

标签: ios objective-c

我正在构建一个使用UIViewController的自定义子类为教程提供视图的教程。我希望有一个带有说明的子视图,然后慢慢淡出。我试图这样做:包装页面控制器类,添加为子视图控制器的自定义UIViewController类,以及添加到自定义UIViewController类视图的动画。

以下是我如何将子视图控制器添加到教程页面视图的示例:

    else if(index==2)

{

    FollowTutorViewController *next1 = [[FollowTutorViewController alloc] init];
    next1.view.userInteractionEnabled = NO;
    next1.typeDisplay = 1;
    next1.index = index;
    [page addChildViewController:next1];
    next1.view.frame = page.view.frame;
    [page.view addSubview:next1.view];
}

以下是我如何在子类UIViewController中执行动画的示例:

- (void)messageTutorial
{

    CGFloat height = [[UIScreen mainScreen] bounds].size.height;
    CGFloat width = [[UIScreen mainScreen] bounds].size.width;

    UILabel *directionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(width/2, height/2, 100, 100)];
    directionsLabel.backgroundColor = ORANGE_COLOR;
    directionsLabel.textColor = BACKGROUND_COLOR;
    directionsLabel.text = @"Follower pages show who you're following and who's following you\n\nYou can also see a list of most-controversial posters when you look for New People \n\nBuzz and Judge to gain followers";
    directionsLabel.font = [UIFont systemFontOfSize:SMALL_FONT_SIZE];

    [directionsLabel setLineBreakMode: UILineBreakModeWordWrap];
    [directionsLabel setNumberOfLines:0];
    CGSize constraint = CGSizeMake(width*.8 , 200000.0f);
    CGSize size = [directionsLabel.text sizeWithFont:[UIFont systemFontOfSize:SMALL_FONT_SIZE] constrainedToSize:constraint];


    directionsLabel.alpha = .8;
    CGRect f = directionsLabel.frame;
    f.size = size;
    directionsLabel.frame = f;
    directionsLabel.center = self.view.center;
    [self.tableView addSubview:directionsLabel];


     [UIView animateWithDuration:15 animations:^{
     directionsLabel.alpha = 0;

     } completion:^(BOOL finished) {
     [directionsLabel removeFromSuperview];

     }]; 
}

我想让标签在用户看到该视图时慢慢消失,但现在当我运行此代码时,无论我在何处调用它,视图在用户查看页面时都消失了。我已经尝试在子自定义UIViewController的viewWillAppear,viewDidAppear,viewDidLayoutSubviews中运行此代码。还有其他建议吗?

0 个答案:

没有答案