UIView使用UIMotionEffect效果
UIView使用UIMotionEffect效果

这个效果在模拟器上看不了,所以无法截图.
UIView+MotionEffect.h + UIView+MotionEffect.m
//
// UIView+MotionEffect.h
//
// Copyright (c) 2014年 Nick Jensen. All rights reserved.
// #import <UIKit/UIKit.h> @interface UIView (MotionEffect) @property (nonatomic, strong) UIMotionEffectGroup *effectGroup; - (void)addXAxisWithValue:(CGFloat)xValue YAxisWithValue:(CGFloat)yValue;
- (void)removeSelfMotionEffect; @end
//
// UIView+MotionEffect.m
//
// Copyright (c) 2014年 Nick Jensen. All rights reserved.
// #import "UIView+MotionEffect.h"
#import <objc/runtime.h> static char motionEffectFlag; @implementation UIView (MotionEffect) -(void)setEffectGroup:(UIMotionEffectGroup *)effectGroup
{
// 清除掉关联
objc_setAssociatedObject(self, &motionEffectFlag,
nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); // 建立关联
objc_setAssociatedObject(self, &motionEffectFlag,
effectGroup, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} -(UIMotionEffectGroup *)effectGroup
{
// 返回关联
return objc_getAssociatedObject(self, &motionEffectFlag);
} - (void)addXAxisWithValue:(CGFloat)xValue YAxisWithValue:(CGFloat)yValue
{
NSLog(@"%p", &motionEffectFlag); if ((xValue >= ) && (yValue >= ))
{
UIInterpolatingMotionEffect *xAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
xAxis.minimumRelativeValue = @(-xValue);
xAxis.maximumRelativeValue = @(xValue); UIInterpolatingMotionEffect *yAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
yAxis.minimumRelativeValue = @(-yValue);
yAxis.maximumRelativeValue = @(yValue); // 先移除效果再添加效果
self.effectGroup.motionEffects = nil;
[self removeMotionEffect:self.effectGroup];
self.effectGroup.motionEffects = @[xAxis, yAxis]; // 给view添加效果
[self addMotionEffect:self.effectGroup];
}
} - (void)removeSelfMotionEffect
{
[self removeMotionEffect:self.effectGroup];
} @end
使用:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"show"]];
[self.view addSubview:imageView];
imageView.center = self.view.center;
imageView.effectGroup = [UIMotionEffectGroup new];
[imageView addXAxisWithValue:.f YAxisWithValue:.f];
}
注意:
给类目添加属性需要重写setter.getter方法哦:)

UIView使用UIMotionEffect效果的更多相关文章
- IOS开发-UIView之动画效果的实现方法(合集)
http://www.cnblogs.com/GarveyCalvin/p/4193963.html 前言:在开发APP中,我们会经常使用到动画效果.使用动画可以让我们的APP更酷更炫,最重要的是优化 ...
- ios UIView常用动画效果
一 //调用 1 2 3 4 5 6 if(m_viewScenario.superview == nil)<br>{ m_viewScenario.alpha = 1.0; ...
- IOS启动页动画(uiview 淡入淡出效果 )2
Appdelegate里面右个这个函数,只要它没结束,你的等待界面就不会消失.以在启动的时候做些动画 - (BOOL)application:(UIApplication *)application ...
- iOS中UIView翻转效果实现
本文转载至 http://baishiyun.blog.163.com/blog/static/13057117920148228261747/ 新建一个view-based模板工程,在ViewCo ...
- iOS开发UIView.h简介
1.UICoordinateSpace不同坐标空间的坐标切换 @protocol UICoordinateSpace <NSObject> //将当前的坐标空间点转换到指定的坐标空间 - ...
- UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线
一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...
- iOS UIView 动画浅谈
UIView 等会效果简单实现,哪一个登录页面的demo来举例子吧. + (void)animateWithDuration:(NSTimeInterval)duration animations:( ...
- 怎样实现UIView的旋转
首先创建界面,在viewDidLoad创建view以及button 相关代码如下 -(void)viewDidLoad { [super viewDidLoad]; viewDemo = [[UIVi ...
- iOS开发——动画篇Swift篇&动画效果的实现
Swift - 动画效果的实现 在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...
随机推荐
- R语言常用包分类总结
常用包: ——数据处理:lubridata ,plyr ,reshape2,stringr,formatR,mcmc: ——机器学习:nnet,rpart,tree,party,lars,boost, ...
- php中接收参数,不论是来自GET还是POST方法
不多说,直接上代码, 其实也就是先用GET的方法去获取,如果值为空,在用POST方法去获取 写下来是为了方便和备忘 function getParam($str){ if ( isset( ...
- Nodejs学习笔记(一)—简介及安装Node.js开发环境
一.简介 Node.js是让Javascript脱离浏览器运行在服务器的一个平台,不是语言: Node.js采用的Javascript引擎是来自Google Chrome的V8:运行在浏览器外不用考虑 ...
- 短视频APP是如何开启你的美好生活的?
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯视频云终端团队发表于云+社区专栏 常青, 2008 年毕业加入腾讯,一直从事客户端研发相关工作,先后参与过 PC QQ.手机QQ. ...
- Asterist搭建步骤
环境: # cat /proc/version Linux version 2.6.18-308.el5 (mockbuild@x86-010.build.bos.redhat.com) (gcc v ...
- springboot 源码笔记
1.springAppication构造器 基于getSpringFactoriesInstances方法构造如下类(获取文件内容在META-INF/spring.factories文件中) 1.1 ...
- idea中maven项目程序包找不到解决办法之一
首先检查maven配置对不对,包括被settings文件以及资源库的位置,maven版本等. 如果不行的话再进行下面的操作: 第一种方案: 在终端terminal中项目目录下,输入“mvn idea: ...
- 2Java基础语法
1.标识符 1.1 标识符以字母.下划线.美元符开头 1.2 标识符由字母.下划线.美元符或数字组成 1.3 标识符区分大小写 1.4 不能与Java关键字同名 ...
- C# 进程优先级和线程优先级的方法
C# 设置进程优先级的方法 this.process1= Process.GetCurrentProcess(); process1.PriorityClass = ProcessPriorityCl ...
- python中函数重载和重写
python 中的重载 在python中,具有重载的思想却没有重载的概念.所以有的人说python这么语言并不支持函数重载,有的人说python具有重载功能.实际上python编程中具有重载的目的缺 ...