创建一个淡出屏幕效果的iphone



我有一个视图控制器....当用户按下一个按钮时,我想要一个黑色的屏幕在顶部逐渐消失,一个uiactivity指示器出现在逐渐消失的屏幕的顶部。

如何让这个动画淡出生效?

-(IBAction) loginToApp:(id)sender{
     //fade in view
}

在视图顶部添加另一个视图,颜色为纯黑色。你可以在IB或编程中做到这一点,只是要确保它有更高的z轴顺序(在顶部)。让它= 0。然后:

-(IBAction) loginToApp:(id)sender{
     [UIView animateWithDuration:1.5 animations:^{ myview.alpha = 1.0; }]
}

…显然你需要一个outlet或变量myview连接到那个视图。1.5 =秒。

当然可以。您可以随心所欲地创建覆盖视图,但这将工作(假设您在某处创建了适当的实例变量)。我的代码在我的视图控制器中,所以[self view]返回我想要遮蔽的视图。

shadeView = [[UIView alloc] initWithFrame:[[self view] bounds]];
shadeView.backgroundColor = [UIColor blackColor];
shadeView.alpha = 0.0f;
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorStyleWhiteLarge];
spinner.center = CGPointMake(CGRectGetMidX([shadeView bounds]),
                             CGRectGetMidY([shadeView bounds]));
[shadeView addSubview:spinner];
[[self view] addSubview:shadeView];

报告:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[spinner startAnimating];
shadeView.alpha = 0.7f;
[UIView commitAnimations];

和隐藏:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[spinner stopAnimating];
shadeView.alpha = 0.0f;
[UIView commitAnimations];

最新更新