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 ...
随机推荐
- Ubuntu系统下OpenDaylight源码编译安装
操作系统:Linux x64 / Ubuntu 14.04 研究领域:软件定义网络SDN (Software-defined Networking) 开发组件:OpenDaylight 声明:转载请注 ...
- 笔记三:python乱码深度剖析一
一:学习内容 python编码转换 python乱码原因深入解析 二:python编码转换 1. Python内部字符串一般都是Unicode编码,代码中字符串的默认编码与代码文件本身的编码是一致的. ...
- java面试⑤前端部分
2.4.1 简单说一下HTML,CSS,javaScript在网页开发中的定位? 2.4.2简单介绍一下AJAX 2.4.3 JS和JQuery的关系 2.4.4 JQuery的常用选择器 2.4.5 ...
- 发布Framework 4.0到iis时,出现HTTP 错误 403.14 - Forbidden
新发布MVC到服务器的时候,经常碰到403.14错误,绝大部分的时候都是因为Framework 4.0需要重新注册下,在运行里输入:C:\Windows\Microsoft.NET\Framework ...
- XRP节点部署
目录 XRP节点部署 准备 硬软件配置(建议) 安装Rippled服务 一. 以Stock Server模型运行 在何种情况下运行此模式 二 .以 Validator模式运行 在何种情况下运行此模式 ...
- springboot jpa 多条件查询(多表)
前几天写的,贴上来. 实体类. package com.syl.demo.daomain; import lombok.Data; import javax.persistence.*; /** * ...
- DOM (文档对象模型(Document Object Model))
文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象 ...
- linux命令新建文件
在命令行输入vi filename就创建了一个叫filename的文件了,如果存在就打开了. 进入vi以后,输入内容,最后按一下esc,再按冒号,输入wq就保存退出了. 新建一个文本文件 vi New ...
- Node.js学习笔记(七) --- Node.js的静态文件托管、路 由、EJS 模板引擎、GET 、POST
1 . Nodejs 静态文件托管静态 web 服务器封装 2 . 路由 官方解释: 路由(Routing)是由一个 URI(或者叫路径)和一个特定的 HTTP 方法(GET.POST 等)组成的, ...
- JAVA成员变量的隐藏
一.如果子类与父类中有一个相同名称的成员变量,那么子类的成员变量会不会覆盖父类的成员变量?我们看下在的例子: public class A { public int x=10; } public cl ...