效果图
self.messageView是自定义的一个UIView,具体的可以根据自己的需求进行设计。
[self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.insets(UIEdgeInsetsZero);
}];
self.messageView.message = @"明天开启中秋假期,我国大部分地区都是晴朗天气,雨雪集中在西藏、四川、云南、贵州、广西一带,道路...>";
[UIView animateWithDuration:0.7 delay:0 options:0 animations:^{
self.messageView.alpha = 0.2;
[self.messageView exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
self.messageView.alpha = 1;
} completion:^(BOOL finished) {
//设置定时器
[NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(displayNews) userInfo:nil repeats:YES];
}];
}
-(void)displayNews{
countInt++;
if (countInt >= self.messageArr.count) {
countInt = 0;
}
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.5f ;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = YES;
animation.type = @"cube";
[self.messageView.layer addAnimation:animation forKey:@"animationID"];
[self.messageView setMessage:self.messageArr[countInt]];
}