做過乙個專案,裡面涉及到的動畫效果比較多,在這裡做個小小的總結。
實現乙個物體在某段時間從乙個點移動到另乙個點。
效果如下:
動畫相關**如下:
動畫模型:
動畫實現:@inte***ce
animationmodel : nsobject
@property(nonatomic,strong) nsarray * images;
@property(nonatomic,assign) float fromx;
@property(nonatomic,assign) float fromy;
@property(nonatomic,assign) float tox;
@property(nonatomic,assign) float toy;
@property(nonatomic,assign) bool loop;
@property(nonatomic,assign) float time;
@end
效果有點像撒花,效果如下:-(void)addsinglelineanimationtoview:(uiview *)view animationmodel:(animationmodel *)model
[view.layer addanimation:moveanimation forkey:@"singlelineanimation"];
}
這個效果的實現也是我在網上找到的,封裝了乙個view和乙個button,呼叫很方便,下面我貼一下呼叫的**,後面會給出完整**的位址。
呼叫**:
效果如下:-(bzfireworkanimationbutton *)praisebutton
return _praisebutton;
}-(void)praiseaction:(bzfireworkanimationbutton *)buttonelse
button.selected = !button.selected;
}
實現**:
-(void)setupheartbeatanimationinview:(uiview *)view
效果如下:
**實現如下:
@inte***ce
floatviewcontroller ()
//判斷是否是當前viewcontroller,如果不是,則停止動畫,否則動畫一直在,且dealloc方法不會被呼叫
@property(nonatomic,assign) bool iscurrentvc;
@end
@implementation
floatviewcontroller
- (void)viewdidload
-(void)dealloc
self
.iscurrentvc = yes;
} self
.iscurrentvc = no;
}-(void)setanimationimageviewanimation:(uiimageview *)animationimageview];
[uiview animatewithduration:1 delay:1 options:uiviewanimationoptioncurveeaseinout animations:^ completion:^(bool finished)
}];}
這種方式需要注意的是animationimages這個陣列裡面的物件是uiimage,所以千萬不要把名稱的陣列直接賦值,會造成崩潰。nsarray * images = @[@"gif_ferriswheel1",@"gif_ferriswheel2",@"gif_ferriswheel3",@"gif_ferriswheel4",@"gif_ferriswheel5",@"gif_ferriswheel6"];
uiimageview * imageviews = [[uiimageview alloc] init];
uiimage * image = [uiimage imagenamed:images[0]];
imageviews.frame = cgrectmake(120, 200, image.size.width, image.size.height);
nsmutablearray * imagesarray = [nsmutablearray array];
for (nsstring * imagesname in images)
imageviews.animationimages = [imagesarray copy];
imageviews.animationduration = 0.9;
imageviews.animationrepeatcount = 1000000000;
[imageviews startanimating];
[self.view addsubview:imageviews];
既有位移的改變,又在改變位移的同時自身在變,比如乙個人走路。
效果如圖:
實現動畫主要**如下:
這個動畫效果涉及到兩個時間,乙個位移從起點到終點的時間和乙個完成一套動作的時間,這兩個時間需要去調才能做出最自然的效果,我這裡提供的是思路,兩個時間沒有花時間去調,請見諒~-(void)initdata
}-(void)setuplinegifanimation
animationimageview.animationimages = [imagesarray copy];
animationimageview.animationduration = 1.2
; animationimageview.animationrepeatcount = 1000000000
; [animationimageview startanimating];
[self.view addsubview:animationimageview];
[self addsinglelineanimationtoview:animationimageview animationmodel:model];
}}-(void)addsinglelineanimationtoview:(uiview *)view animationmodel:(animationmodel *)model
[view.layer addanimation:moveanimation forkey:@"linegifanimation"];
}
iOS動畫效果和實現
動畫效果提供了狀態或頁面轉換時流暢的使用者體驗,在ios系統中,咱們不需要自己編寫繪製動畫的 core animation提供了豐富的api來實現你需要的動畫效果。uikit只用uiview來展示動畫,動畫支援uiview下面的這些屬性改變 1 commitanimations方式使用uiview動...
iOS 動畫效果
最普通動畫 開始動畫 uiview beginanimations nil context nil 設定動畫持續時間 uiview setanimationduration 2 動畫的內容 frame.origin.x 150 img setframe frame 動畫結束 uiview commi...
iOS 動畫效果
最普通動畫 開始動畫 uiview beginanimations nil context nil 設定動畫持續時間 uiview setanimationduration 2 動畫的內容 frame.origin.x 150 img setframe frame 動畫結束 uiview commi...