Ios 如何在子视图控制器的视图实际出现时启动动画?
我正在构建一个教程,它使用UIViewController的自定义子类为教程提供视图。我希望有一个子视图与指示出现,然后慢慢淡出。我尝试这样做:包装页控制器类,作为子视图控制器添加的自定义UIViewController类,以及添加到自定义UIViewController类视图的动画 以下是如何将子视图控制器添加到教程页面视图的示例:Ios 如何在子视图控制器的视图实际出现时启动动画?,ios,objective-c,Ios,Objective C,我正在构建一个教程,它使用UIViewController的自定义子类为教程提供视图。我希望有一个子视图与指示出现,然后慢慢淡出。我尝试这样做:包装页控制器类,作为子视图控制器添加的自定义UIViewController类,以及添加到自定义UIViewController类视图的动画 以下是如何将子视图控制器添加到教程页面视图的示例: else if(index==2) { FollowTutorViewController *next1 = [[FollowTutorVie
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的ViewWillDisplay、ViewDidDisplay、ViewDidLayoutSubView中运行此代码。还有其他建议吗?你能发布包含该动画的整个方法吗?你看到FollowTutorViewController的视图了吗?您在哪里制作控制器、故事板或xib?您的代码在viewDidAppear中对我很好。@rdelmar是的,我看到的是FollowTutorViewController的视图,它应该是这样的。如果我注释掉动画,我会看到directionsLabel,就像我应该看到的一样。但如果我设置动画,我想它会在我看到它之前被初始化并消失。如果我在动画中放一个日志,我确实看到了打印出来的结果。那么你的理论是动画开始和结束得太快了?嗯,您可以指定动画开始时间的延迟。那为什么不试试呢?如果你这样做,它能解决问题吗?如果我延迟,它能工作。但这是不精确的,因为我必须猜测正确的时间,而且可能会因设备而异。