IOS UIView的淡入淡出效果

来源:互联网 发布:河北工商学院知乎 编辑:程序博客网 时间:2024/05/22 02:41

- (void)viewDidLoad

{

    [superviewDidLoad];

    // Do any additional setup after loading the view from its nib.

    timer=[NSTimerscheduledTimerWithTimeInterval:3

                                          target:self

                                        selector:@selector(showArrow)

                                        userInfo:nil

                                         repeats:YES];

}

-(void)showArrow{

    UIImageView *arrow =(UIImageView *) [self.viewviewWithTag:101];

    [UIViewbeginAnimations:@"ShowArrow"context:nil];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];

    [UIViewsetAnimationDuration:1.0];

    [UIViewsetAnimationDelegate:self];

    [UIViewsetAnimationDidStopSelector:@selector(showArrowDidStop:finished:context:)];

    // Make the animatable changes.

    arrow.alpha =0.0;

    // Commit the changes and perform the animation.

    [UIViewcommitAnimations];

}

// Called at the end of the preceding animation.


- (void)showArrowDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context


{

    UIImageView *arrow =(UIImageView *) [self.viewviewWithTag:101];

    [UIViewbeginAnimations:@"HideArrow"context:nil];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseOut];

    [UIViewsetAnimationDuration:1.0];

    [UIViewsetAnimationDelay:1.0];

    arrow.alpha =1.0;

    [UIViewcommitAnimations];

    

}