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

相关文章

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

macOS怎么轻松更换App图标? Mac电脑图标更换指南

《macOS怎么轻松更换App图标?Mac电脑图标更换指南》想要给你的Mac电脑按照自己的喜好来更换App图标?其实非常简单,只需要两步就能搞定,下面我来详细讲解一下... 虽然 MACOS 的个性化定制选项已经「缩水」,不如早期版本那么丰富,www.chinasem.cn但我们仍然可以按照自己的喜好来更换

最好用的WPF加载动画功能

《最好用的WPF加载动画功能》当开发应用程序时,提供良好的用户体验(UX)是至关重要的,加载动画作为一种有效的沟通工具,它不仅能告知用户系统正在工作,还能够通过视觉上的吸引力来增强整体用户体验,本文给... 目录前言需求分析高级用法综合案例总结最后前言当开发应用程序时,提供良好的用户体验(UX)是至关重要

基于Python实现PDF动画翻页效果的阅读器

《基于Python实现PDF动画翻页效果的阅读器》在这篇博客中,我们将深入分析一个基于wxPython实现的PDF阅读器程序,该程序支持加载PDF文件并显示页面内容,同时支持页面切换动画效果,文中有详... 目录全部代码代码结构初始化 UI 界面加载 PDF 文件显示 PDF 页面页面切换动画运行效果总结主

React实现原生APP切换效果

《React实现原生APP切换效果》最近需要使用Hybrid的方式开发一个APP,交互和原生APP相似并且需要IM通信,本文给大家介绍了使用React实现原生APP切换效果,文中通过代码示例讲解的非常... 目录背景需求概览技术栈实现步骤根据 react-router-dom 文档配置好路由添加过渡动画使用

Qt QWidget实现图片旋转动画

《QtQWidget实现图片旋转动画》这篇文章主要为大家详细介绍了如何使用了Qt和QWidget实现图片旋转动画效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、效果展示二、源码分享本例程通过QGraphicsView实现svg格式图片旋转。.hpjavascript

【前端学习】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的功能,即该应用程序