UIWindow动画

G33*_*z0r 7 iphone ipad ios4

我目前使用自定义UIWindow来显示自定义警报视图,使其看起来像Apple风格.当我删除它时,它不会自动淡出,sk我决定使用UIView动画并将alpha更改为0然后删除它但是仍然没有做到这一点.你们想知道该怎么办吗?

Tom*_*ift 9

对于我自己的自定义AlertView类使用的褪色背景窗口(类似于你正在做的事情),我创建了一个自定义UIWindow并覆盖了makeKeyAndVisible,但你也可以在类的上下文之外执行此操作:

- (void)makeKeyAndVisible
{
    self.backgroundColor = [UIColor clearColor];
    self.alpha = 0;

    [UIView beginAnimations: @"fade-in" context: nil];

    [super makeKeyAndVisible];

    self.alpha = 1;

    [UIView commitAnimations];
}

- (void)resignKeyWindow
{
    self.alpha = 1;

    [UIView beginAnimations: @"fade-out" context: nil];

    [super resignKeyWindow];

    self.alpha = 0;

    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)


Abr*_*odj 1

尝试这个:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationBeginsFromCurrentState:YES];

greyWindow.alpha = 0;

[UIView commitAnimations];  
Run Code Online (Sandbox Code Playgroud)