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. Django配置celery执行异步任务和定时任务

    原生celery,非djcelery模块,所有演示均基于Django2.0 celery是一个基于python开发的简单.灵活且可靠的分布式任务队列框架,支持使用任务队列的方式在分布式的机器/进程/线 ...

  2. IOC给程序带来的好处

    IOC(inversion of control)的中文解释是“控制反转”或者“依赖注入”,它的实现目的是:我们可以通过配置文件来控制程序的流程,达到程序代码的优化.初学者往往弄不清楚为什么我们可以通 ...

  3. 消息队列系列(二):.Rabbitmq的使用及Web监控工具使用

    一.文档资料        1.官方网站:http://www.rabbitmq.com/        2.安装教程:http://www.rabbitmq.com/install-windows. ...

  4. xmpp实现的即时通讯聊天(一)

    参考网址:http://www.jianshu.com/p/b401ad6ba1a7 http://www.jianshu.com/p/4edbae55a07f 一.mysql和openfire环境的 ...

  5. oracle 合并列的函数wm_concat

    oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_concat(column)函数实现字段合并,如果您对oracle wm_concat( ...

  6. 二:java常用快捷键

    ctrl+F6 切换编辑器 Ctrl+E 快速显示当前Editer的下拉列表 Ctrl+1 快速修复 Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Alt+Shif ...

  7. 【转】Spring事务异常回滚,捕获异常不抛出就不会回滚

    最近遇到了事务不回滚的情况,我还考虑说JPA的事务有bug? 我想多了.......     为了打印清楚日志,很多方法我都加tyr catch,在catch中打印日志.但是这边情况来了,当这个方法异 ...

  8. Java Swing实战(二)下拉菜单组件JComboBox及其事件监听

    接下来给"数据源配置"面板添加下拉框. /** * @author: lishuai * @date: 2018/11/26 13:51 */ public class Weimi ...

  9. Windows应用程序对键盘与鼠标的响应

      编写程序: 设计一个窗口, 当单击鼠标左键时, 窗口中显示"LEFT BUTTON"; 当单击鼠标右键时, 窗口中显示"RIGHT BUTTON"; 当单击 ...

  10. Zookeeper学习文章目录1

    目录:参考文章如下 1.ZooKeeper学习第一期---Zookeeper简单介绍 2. ZooKeeper学习第二期--ZooKeeper安装配置 3. ZooKeeper学习第三期---Zook ...