iOS 高仿《掌上生活》app 动画

2023-10-09 02:20
文章标签 app ios 动画 生活 高仿 掌上

本文主要是介绍iOS 高仿《掌上生活》app 动画,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前几天突然看到了招商银行的《掌上生活》app ,看到她的首页的动画还有点意思,然后我就模仿写了一个高仿的掌上生活。

具体用到了重力感应和CABasicAnimation方法:

代码如下:

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>#define Accelerometer_Notice_Windage  0.03
#define DegreesToRadians(x) (M_PI * x / 180.0)@interface ViewController (){UIView *rightDown;UIView *leftdown;UIView *rightUp;UIView *leftup;float lastAccelerationX;float lastAccelerationY;float lastAccelerationZ;NSMutableArray* animationViewArray;
}@end@implementation ViewController- (void)viewDidLoad
{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.[[UIAccelerometer sharedAccelerometer] setDelegate:self];lastAccelerationX=0;lastAccelerationY=0;lastAccelerationZ=0;animationViewArray=[[NSMutableArray alloc]init];self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];UIImageView *headerBG=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 46)];headerBG.image=[UIImage imageNamed:@"navigation.png"];headerBG.userInteractionEnabled=YES;[self.view   addSubview:headerBG];[headerBG release];UIImageView *cmblogo=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 88, 26)];cmblogo.image=[UIImage imageNamed:@"logo.png"];[headerBG   addSubview:cmblogo];[cmblogo release];UIImageView *titleimage=[[UIImageView alloc]initWithFrame:CGRectMake(110, 10, 93, 26)];titleimage.image=[UIImage imageNamed:@"font.png"];[headerBG   addSubview:titleimage];[titleimage release];UIButton *loginbutton=[UIButton buttonWithType:UIButtonTypeCustom];loginbutton.frame=CGRectMake(260,6, 50, 36);[loginbutton setBackgroundImage:[UIImage imageNamed:@"btm_nav.png"] forState:UIControlStateNormal];[loginbutton setBackgroundImage:[UIImage imageNamed:@"btm_nav.png"] forState:UIControlStateNormal];[loginbutton addTarget:self action:@selector(doanimation) forControlEvents:UIControlEventTouchUpInside];[loginbutton setTitle:@"登录" forState:UIControlStateNormal];[loginbutton setTitle:@"登录" forState:UIControlStateHighlighted];[headerBG addSubview:loginbutton];//便利生活view设置leftdown=[[UIImageView alloc]initWithFrame:CGRectMake(16,45,122,258)];leftdown.backgroundColor=[UIColor clearColor];[self.view addSubview:leftdown];[animationViewArray addObject:leftdown];[leftdown release];UIImageView *bianliImageButton=[[UIImageView alloc]initWithFrame:CGRectMake(5,164,122,91)];bianliImageButton.image=[UIImage imageNamed:@"note_bl.png"];[leftdown   addSubview:bianliImageButton];[bianliImageButton release];UIImageView *bianlishenghuoImage=[[UIImageView alloc]initWithFrame:CGRectMake(60,0,10, 175)];bianlishenghuoImage.image=[UIImage imageNamed:@"rope_lang-.png"];[leftdown   addSubview:bianlishenghuoImage];[bianlishenghuoImage release];//帐单还款view设置leftup=[[UIImageView alloc]initWithFrame:CGRectMake(48,45,122,148)];leftup.backgroundColor=[UIColor clearColor];[self.view addSubview:leftup];[animationViewArray addObject:leftup];[leftup release];UIImageView *zhangdanImageButton=[[UIImageView alloc]initWithFrame:CGRectMake(1,56,125,91)];zhangdanImageButton.image=[UIImage imageNamed:@"note_cx.png"];[leftup addSubview:zhangdanImageButton];[zhangdanImageButton release];UIImageView *zhangdanhaikuanImage=[[UIImageView alloc]initWithFrame:CGRectMake(60,0,10, 70)];zhangdanhaikuanImage.image=[UIImage imageNamed:@"rope.png"];[leftup   addSubview:zhangdanhaikuanImage];[zhangdanhaikuanImage release];//用卡服务view设置rightDown=[[UIImageView alloc]initWithFrame:CGRectMake(160,45,122,251)];rightDown.backgroundColor=[UIColor clearColor];[self.view addSubview:rightDown];[animationViewArray addObject:rightDown];[rightDown release];UIImageView *yongkaImageButton=[[UIImageView alloc]initWithFrame:CGRectMake(5,163,122,90)];yongkaImageButton.image=[UIImage imageNamed:@"note_zs_a.png"];[rightDown   addSubview:yongkaImageButton];[yongkaImageButton release];UIImageView *fuwuImage=[[UIImageView alloc]initWithFrame:CGRectMake(60,0,10,175)];fuwuImage.image=[UIImage imageNamed:@"rope_lang-.png"];[rightDown   addSubview:fuwuImage];[fuwuImage release];//缤纷优惠view设置rightUp=[[UIImageView alloc]initWithFrame:CGRectMake(180,45,122,148)];rightUp.backgroundColor=[UIColor clearColor];[self.view addSubview:rightUp];[animationViewArray addObject:rightUp];[rightUp release];UIImageView *bfImageButton=[[UIImageView alloc]initWithFrame:CGRectMake(2,60,125,88)];bfImageButton.image=[UIImage imageNamed:@"note_bf.png"];[rightUp  addSubview:bfImageButton];[bfImageButton release];UIImageView *youhuiImage=[[UIImageView alloc]initWithFrame:CGRectMake(58,0,10, 70)];youhuiImage.image=[UIImage imageNamed:@"rope_lang-.png"];[rightUp  addSubview:youhuiImage];[youhuiImage release];UIImageView *arrowImage=[[UIImageView alloc]initWithFrame:CGRectMake(0,44,320, 19)];arrowImage.image=[UIImage imageNamed:@"arrowall2.png"];[self.view   addSubview:arrowImage];[arrowImage release];}-(void)doanimation{NSArray* tempXPoint=[[NSArray alloc]initWithObjects:@"77",@"109",@"221",@"241",nil];for (int i=0; i<[animationViewArray count]; i++){[self doWiggle:[animationViewArray objectAtIndex:i]  startPoint:[tempXPoint objectAtIndex:i]];}[tempXPoint release];
}-(void)doWiggle:(UIView *)touchView startPoint:(NSString *)string{CALayer *touchedLayer = [touchView layer];float xpoint=[string floatValue];const CGFloat boneScale = 1;CATransform3D scale = CATransform3DMakeScale(boneScale , boneScale, 1);touchedLayer.position = CGPointMake(xpoint,45);touchedLayer.anchorPoint = CGPointMake(0.5, 0.0);touchedLayer.bounds = CGRectMake(0,0,122,88);touchedLayer.transform = scale;CABasicAnimation* r1 = [CABasicAnimation animationWithKeyPath:@"transform"];CATransform3D rot1 = CATransform3DMakeRotation(0.5, 0,0,1);rot1 = CATransform3DConcat(rot1, touchedLayer.transform);r1.toValue = [NSValue valueWithCATransform3D:rot1];r1.autoreverses = YES;r1.repeatCount = NO;r1.duration = 0.5;r1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];[touchedLayer addAnimation:r1 forKey:nil];}#pragma mark -
#pragma mark UIAccelerometerDelegate-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {//    NSLog(@"==%f,%f", acceleration.x,lastAccelerationX);
//    NSLog(@"%f",ABS(lastAccelerationX-acceleration.x));if( ABS(lastAccelerationX-acceleration.x)>Accelerometer_Notice_Windage &&ABS(lastAccelerationY-acceleration.y)>Accelerometer_Notice_Windage &&ABS(lastAccelerationZ-acceleration.z)>Accelerometer_Notice_Windage ){NSLog(@"asdfasf");[self doanimation];}lastAccelerationX=acceleration.x;lastAccelerationY=acceleration.y;lastAccelerationZ=acceleration.z;}
效果:


效果:


效果:



源代码下载

其他功能还在完善,敬请期待!

这篇关于iOS 高仿《掌上生活》app 动画的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/169648

相关文章

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

【iOS】MVC模式

MVC模式 MVC模式MVC模式demo MVC模式 MVC模式全称为model(模型)view(视图)controller(控制器),他分为三个不同的层分别负责不同的职责。 View:该层用于存放视图,该层中我们可以对页面及控件进行布局。Model:模型一般都拥有很好的可复用性,在该层中,我们可以统一管理一些数据。Controlller:该层充当一个CPU的功能,即该应用程序

用Unity2D制作一个人物,实现移动、跳起、人物静止和动起来时的动画:中(人物移动、跳起、静止动作)

上回我们学到创建一个地形和一个人物,今天我们实现一下人物实现移动和跳起,依次点击,我们准备创建一个C#文件 创建好我们点击进去,就会跳转到我们的Vision Studio,然后输入这些代码 using UnityEngine;public class Move : MonoBehaviour // 定义一个名为Move的类,继承自MonoBehaviour{private Rigidbo

MFC中App,Doc,MainFrame,View各指针的互相获取

纸上得来终觉浅,为了熟悉获取方法,我建了个SDI。 首先说明这四个类的执行顺序是App->Doc->Main->View 另外添加CDialog类获得各个指针的方法。 多文档的获取有点小区别,有时间也总结一下。 //  App void CSDIApp::OnApp() {      //  App      //  Doc     CDocument *pD

动画AnimationDrawable、转动

现实开发中:很多地方都用到 点击动画的特效; 本案例本人做了三个关于“动” 画 的效果; 先上图: 总体图: A: B: 1:点击图片按钮,效果是:图片闪动; 通过在xml中定义:标签:animation-list来实现点击动画的效果;  是否循环标签:oneshot ;   时间间隔标签:duration ; 要显示的图片标签:drawable ;

13 transition数组的动画使用

划重点 动画:transitiontransition-group :数组动画数组的 添加 / 删除 豆腐粉丝汤 清淡又健康 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><me

12 动画transition的使用2

划重点 Vue 动画:transition / transform在动画周期中执行动动画(上一篇是通过动画样式控制动画) 清蒸扇贝 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><

ConstraintLayout布局里的一个属性app:layout_constraintDimensionRatio

ConstraintLayout 这是一个约束布局,可以尽可能的减少布局的嵌套。有一个属性特别好用,可以用来动态限制宽或者高app:layout_constraintDimensionRatio 关于app:layout_constraintDimensionRatio参数 app:layout_constraintDimensionRatio=“h,1:1” 表示高度height是动态变化