我有幾張圖片想切換。有一個簡單的功能,我對取得這樣做:使用NSTimer切換圖像
-(void)imageSlide{
if (!isMoved){
CGRect frame = self.imageSlideshow.frame;
frame.origin.x = self.imageSlideshow.frame.origin.x - 320;
self.imageSlideshow.frame = frame;
NSLog(@"1 caze work");
isMoved = YES;
}
if (isMoved){
CGRect frame = self.imageSlideshow.frame;
frame.origin.x = self.imageSlideshow.frame.origin.x + 320;
self.imageSlideshow.frame = frame;
NSLog(@"2 caze work");
isMoved = NO;
}
}
有它的NSTimer調用該函數:
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(imageSlide)
userInfo:nil
repeats:YES];
BOOL isMoved;
放在實現類。
我想要的是,刪除圖像,然後,再次顯示(並每2秒重複一次)。擁有流暢的動畫效果也不錯。
該代碼:
for (int i=0; i<99; i++){
self.imageSlideshow.image = [UIImage imageNamed:(i % 2) ? @"ipd1.jpg" : @"ipd2.jpg"];
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.imageSlideshow.layer addAnimation:transition forKey:nil];
}
而且不工作,不知道爲什麼。圖像靜止不動。我沒有導入石英庫幷包含標題。
http://stackoverflow.com/questions/7638831/fade-dissolve-when-changing-uiimageviews-image/38350024#38350024 – 2016-07-13 11:27:17