1 tabar的點(diǎn)擊動(dòng)畫(huà)
效果:
聲明:
這個(gè)效果是根據(jù)龍同學(xué)的博客寫(xiě)成的垛孔。當(dāng)然他那邊是OC版本的,我自己稍微翻譯了一下愿伴,改成了swift版本
swift3.0代碼:
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
var index:NSInteger?
index = self.tabBar.items?.index(of: item)
animationWithIndex(index!)
}
func animationWithIndex(_ index :NSInteger){
var tabbarbuttonArray : Array<UIView?> = []
for tabBarButton in (self.tabBar.subviews) {
if tabBarButton.isKind(of: NSClassFromString("UITabBarButton")!){
tabbarbuttonArray.append(tabBarButton)
}
}
let pulse = CABasicAnimation.init(keyPath: "transform.scale")
pulse.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
pulse.duration = 0.08;
pulse.repeatCount = 1;
pulse.autoreverses = true;
pulse.fromValue = NSNumber.init(value: 0.7)
pulse.toValue = NSNumber.init(value: 1.3)
tabbarbuttonArray[index]?.layer.add(pulse,forKey:nil)
}
2 廣告欄動(dòng)畫(huà)
效果:
聲明:
這個(gè)是很久之前網(wǎng)上看到的一個(gè)效果趟咆,自己加了點(diǎn)東西,至于是哪個(gè)鏈接這里已經(jīng)記不清楚了渺蒿,若原作者看到可以簡(jiǎn)信我痢士,加個(gè)原文鏈接。
OC代碼如下:
將一個(gè)定時(shí)器寫(xiě)在UIScrollView的代理中
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[timer invalidate];
timer = nil;
timer = [NSTimer scheduledTimerWithTimeInterval: kAnimationTime
target: self
selector: @selector(autoScroll:)
userInfo: nil
repeats: YES];
}
- (void)autoScroll:(NSTimer *)sender {
[UIView animateWithDuration:0.5 animations:^{
//[_scrollView setContentOffset:CGPointMake(SCROLL_VIEW_WIDTH * 2, 0) animated:NO];
[self transitionAnimation:YES andAnimationMode:7];
} completion:^(BOOL finished) {
[self moveRight];
}];
}
-(void)transitionAnimation:(BOOL)isNext andAnimationMode:(int)mode
{
//動(dòng)畫(huà)模式
NSArray *animationModeArr=@[@"cube", @"moveIn", @"reveal", @"fade",@"pageCurl", @"pageUnCurl", @"suckEffect", @"rippleEffect", @"oglFlip"];
//1.創(chuàng)建轉(zhuǎn)場(chǎng)動(dòng)畫(huà)對(duì)象
CATransition *transition=[[CATransition alloc]init];
//2.設(shè)置動(dòng)畫(huà)類(lèi)型,注意對(duì)于蘋(píng)果官方?jīng)]公開(kāi)的動(dòng)畫(huà)類(lèi)型只能使用字符串茂装,并沒(méi)有對(duì)應(yīng)的常量定義
//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"
transition.type = animationModeArr[mode];
//設(shè)置子類(lèi)型 (動(dòng)畫(huà)的方向)
if (isNext) {
transition.subtype=kCATransitionFromRight; //右
}else{
transition.subtype=kCATransitionFromRight; //左
}
//設(shè)置動(dòng)畫(huà)時(shí)間
transition.duration=1.0f;
//3.設(shè)置轉(zhuǎn)場(chǎng)后的新視圖添加轉(zhuǎn)場(chǎng)動(dòng)畫(huà)
//self.centerImageView.image=[self getImage:isNext];
//加載動(dòng)畫(huà)
[self.centerImageView.layer addAnimation:transition forKey:@"KCTransitionAnimation"];
}
效果圖中的效果是動(dòng)畫(huà)模式數(shù)組中的第7個(gè)對(duì)象 "rippleEffect"水滴??效果怠蹂。
以上。