iOS實現(xiàn)圖片折疊效果
本文實例為大家分享了iOS實現(xiàn)圖片折疊效果的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:
結(jié)構(gòu)布局:拖兩個UIImageView到控制器,設(shè)置相同的frame和圖片,再拖一個大的UIImageView蓋在上面,注意把大的imageView.userInteractionEnabled = YES;能夠添加手勢。
注意層次結(jié)構(gòu):
核心代碼:
// // ViewController.m // 圖片折疊 // // Created by llkj on 2017/8/31. // Copyright © 2017年 LayneCheung. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *topImageV; @property (weak, nonatomic) IBOutlet UIImageView *buttomImageV; @property (nonatomic, weak) CAGradientLayer *gradientL; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //1.讓上不圖片只顯示上半部分 self.topImageV.layer.contentsRect = CGRectMake(0, 0, 1, 0.5); //2.讓下不圖片只顯示下半部分 self.buttomImageV.layer.contentsRect = CGRectMake(0, 0.5, 1, 0.5); self.topImageV.layer.anchorPoint = CGPointMake(0.5, 1); self.buttomImageV.layer.anchorPoint = CGPointMake(0.5, 0); //設(shè)置漸變層 CAGradientLayer *gradidentL = [CAGradientLayer layer]; gradidentL.frame = self.buttomImageV.bounds; gradidentL.opacity = 0; gradidentL.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor]; self.gradientL = gradidentL; [self.buttomImageV.layer addSublayer:gradidentL]; } //這里也可以手動給大的ImageView添加一個UIPanGestureRecognizer手勢 - (IBAction)pan:(UIPanGestureRecognizer *)pan { //獲取移動的偏移量 CGPoint transP = [pan translationInView:pan.view]; //讓上部圖片開始旋轉(zhuǎn) CGFloat angle = transP.y * M_PI / 200; //近大遠(yuǎn)小效果 CATransform3D transform = CATransform3DIdentity; //眼睛離屏幕的距離(透視效果) transform.m34 = -1 / 300.0; self.gradientL.opacity = transP.y * 1 / 200.0; self.topImageV.layer.transform = CATransform3DRotate(transform, -angle, 1, 0, 0); if (pan.state == UIGestureRecognizerStateEnded) { self.gradientL.opacity = 0; //上部圖片復(fù)位 //usingSpringWithDamping:彈性系數(shù) [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{ self.topImageV.layer.transform = CATransform3DIdentity; } completion:^(BOOL finished) { }]; } } @end
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS仿微博導(dǎo)航欄動畫(CoreGraphics)的實現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于iOS仿微博導(dǎo)航欄動畫(CoreGraphics)的實現(xiàn)方法,文章最后給出了完整的示例代碼,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-07-07iOS端React Native差異化增量更新的實現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于iOS端React Native差異化增量更新的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06iPhone/iPad開發(fā)通過LocalNotification實現(xiàn)iOS定時本地推送功能
這篇文章主要介紹了iPhone/iPad開發(fā)之通過LocalNotification實現(xiàn)iOS定時本地推送功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09