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效果的更多相关文章

  1. IOS开发-UIView之动画效果的实现方法(合集)

    http://www.cnblogs.com/GarveyCalvin/p/4193963.html 前言:在开发APP中,我们会经常使用到动画效果.使用动画可以让我们的APP更酷更炫,最重要的是优化 ...

  2. ios UIView常用动画效果

    一 //调用 1 2 3 4 5 6 if(m_viewScenario.superview == nil)<br>{     m_viewScenario.alpha = 1.0;    ...

  3. IOS启动页动画(uiview 淡入淡出效果 )2

    Appdelegate里面右个这个函数,只要它没结束,你的等待界面就不会消失.以在启动的时候做些动画 - (BOOL)application:(UIApplication *)application ...

  4. iOS中UIView翻转效果实现

    本文转载至  http://baishiyun.blog.163.com/blog/static/13057117920148228261747/ 新建一个view-based模板工程,在ViewCo ...

  5. iOS开发UIView.h简介

    1.UICoordinateSpace不同坐标空间的坐标切换 @protocol UICoordinateSpace <NSObject> //将当前的坐标空间点转换到指定的坐标空间 - ...

  6. UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线

    一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...

  7. iOS UIView 动画浅谈

    UIView 等会效果简单实现,哪一个登录页面的demo来举例子吧. + (void)animateWithDuration:(NSTimeInterval)duration animations:( ...

  8. 怎样实现UIView的旋转

    首先创建界面,在viewDidLoad创建view以及button 相关代码如下 -(void)viewDidLoad { [super viewDidLoad]; viewDemo = [[UIVi ...

  9. iOS开发——动画篇Swift篇&动画效果的实现

    Swift - 动画效果的实现   在iOS中,实现动画有两种方法.一个是统一的animateWithDuration,另一个是组合出现的beginAnimations和commitAnimation ...

随机推荐

  1. 数据库-SQLite简介

    SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库(轻型数据库). 由于资源占用少.性能良好和零管理成本,嵌入式数据库有了它的用武之地,像Android.iPhone都有内置的S ...

  2. Cookie文件说明及IE的Cookie文件格式

    1.Cookie文件的实质 Cookie实际上是Web服务端与客户端(典型的是浏览器)交互时彼此传递的一部分内容,内容可以是任意的,但要在允许的长度范围之内.客户端会将它保存在本地机器上(如IE便会保 ...

  3. ASP.NET Core 中的实时框架 SingalR

    目录 SignalR 是什么? 在 ASP.NET Core 中使用 SignalR 权限验证 横向扩展 源代码 参考 SignalR 是什么? ASP.NET Core SignalR 是一个开源的 ...

  4. Apache POI导出excel

    public String exportXls(HttpServletRequest request, HttpServletResponse response) { try { HSSFWorkbo ...

  5. puts,p,print的区别

    共同点:都是用来屏幕输出的. 不同点: puts 输出内容后,会自动换行(如果内容参数为空,则仅输出一个换行符号):另外如果内容参数中有转义符,输出时将先处理转义再输出 p 基本与puts相同,但不会 ...

  6. Java中Date与String的相互转换

    我们在注册网站的时候,往往需要填写个人信息,如姓名,年龄,出生日期等,在页面上的出生日期的值传递到后台的时候是一个字符串,而我们存入数据库的时候确需要一个日期类型,反过来,在页面上显示的时候,需要从数 ...

  7. Sourcetree报错: 您没有已经配置扩展集成设置的远端

    一.错误提示 您没有已经配置扩展集成设置的远端; ... 二.解决 配置 Legacy Account Settings 即可:

  8. 规范大于编码-我的javaWeb开发规范

    1.应用名称和数据库名称一致 2.javaBean类名称+s和数据库表名一致 3.返回一条数据时,变量名为javaBean类名称的小写;返回多条数据时,变量名为javaBean类名称的大写 4.jav ...

  9. java获得Tomcat服务器的根目录下的内容

    File f2=new File(System.getProperty("catalina.home")+ File.separator+"webapps"+F ...

  10. Asp.Net Mvc表单提交(批量提交)

    Asp.Net Mvc中Action的参数可以自动接收和反序列化form表单的值, 采用form表单提交 name=value类型,只要Action参数的变量名和input的name相同就行 html ...