走马灯
NSString *str = @"人生若只如初见,何事秋风悲画扇。";
self.scrollLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,self.view.frame.size.width, 44)];
self.scrollLabel.text = str;
[self.view addSubview:self.scrollLabel];
self.secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.scrollLabel.frame.origin.x+self.scrollLabel.frame.size.width, self.scrollLabel.frame.origin.y, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height)];
self.secondLabel.font = self.scrollLabel.font;
self.secondLabel.text = self.scrollLabel.text;
[self.view addSubview:self.secondLabel];
[self addAnimation];
- (void)addAnimation{
CGRect scrollFrame = self.scrollLabel.frame;
CGRect secondFrame = self.secondLabel.frame;
[UIView animateWithDuration:4 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
self.scrollLabel.frame = CGRectMake(-self.scrollLabel.frame.size.width, self.scrollLabel.frame.origin.y, self.scrollLabel.frame.size.width, self.scrollLabel.frame.size.height);
self.secondLabel.frame = CGRectMake(0, self.secondLabel.frame.origin.y, self.secondLabel.frame.size.width, self.secondLabel.frame.size.height);
} completion:^(BOOL finished) {
self.scrollLabel.frame = scrollFrame;
self.secondLabel.frame = secondFrame;
[self addAnimation];
}];
}
网友评论