網頁開發中年跑馬燈的<marquee>代碼是經常用到的,一般用來提示或者消息等。在iOS的開發中,我們或許也會用到這種效果。下面就是iOS中實現跑馬燈效果的代碼片段:
[labelShow sizeToFit];
CGRect frame = labelShow.frame;
frame.origin.x = 320;
labelShow.frame = frame;
[UIView beginAnimations:@"testAnimation" context:NULL];
[UIView setAnimationDuration:8.8f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:999999];
frame = labelShow.frame;
frame.origin.x = -frame.size.width;
labelShow.frame = frame;
[UIView commitAnimations];