mark:
iOS那些簡(jiǎn)單的動(dòng)畫(不定期更新)
iOS動(dòng)畫詳解(學(xué)習(xí)動(dòng)畫看這一篇就夠了)
ios?平移與抖動(dòng)動(dòng)畫的簡(jiǎn)單實(shí)現(xiàn)
[UIView animateWithDuration:.5 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.settingAdreView.frame =CGRectMake(5,(ScreenHeight-64-49)/2-350/2, settingAdreViewW, settingAdreViewH);
} completion:^(BOOL finished) {
}];
- (void)createGoodsDetailViewWithShoppingType:(XYShoppingType)shoppingType{
XYGoodsDetailView *xycv = [XYGoodsDetailView createXYGoodsDetailViewWithDelegate:self xYGoodsInfo:_xYGoodsInfo allOtherList:_allOtherList shoppingType:shoppingType bannerList:_bannerList xlOrderForm:(XlOrderForm *)_xlOrderForm];
UIWindow *keywindow = [UIApplication sharedApplication].delegate.window;
// UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow];
xycv.frame = [UIScreen mainScreen].bounds;
[keywindow addSubview:xycv];
xycv.blackBackground.alpha=0.0;
xycv.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
[UIView animateWithDuration:0.3 animations:^(void) {
xycv.blackBackground.alpha=0.5;
xycv.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
//此處可做UIView漸變效果以及飛出效果
} completion:^(BOOL finished) {
}];
// [self addDetailViewWithAnimationWithHolderView:xycv];
}
- (void)childViewRemoveFromSuperview{
self.blackBackground.alpha=0.0;
[UIView animateWithDuration:0.3 animations:^(void) {
self.frame = CGRectMake(0, ScreenHeight, ScreenWidth, ScreenHeight);
//此處可做UIView漸變效果以及飛出效果
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
上面這種動(dòng)畫的好處在于動(dòng)畫過程可控,而且還可以用于removeFromSuperview這種特殊的情況。但是麻煩,像這種動(dòng)畫彈出收起的效果要通過set Frame來實(shí)現(xiàn)。
//動(dòng)畫
- (void)addAnimationWithCurrentAnimationView:(UIView *)CurrentAnimationView{
CATransition *animation = [CATransition animation];
animation.type = @"push";
animation.subtype = kCATransitionFromTop;
animation.duration = 0.2;
[CurrentAnimationView.layer addAnimation:animation forKey:nil];
}
第二種方法的優(yōu)點(diǎn)在于效果可選的多,方便使用,缺點(diǎn)是動(dòng)畫不可控。另外要特別注意的是動(dòng)畫view,本身的layer層加動(dòng)畫。比如說我要在keyWindow上add一個(gè)subView,那么就是subView的layer加動(dòng)畫而不是keyWindow