├── .gitignore ├── 802473389dd1140ac59e2e8dc29518fc.gif ├── README.md └── YGGrivityImageView ├── YGGravityImageView ├── YGGravity.h ├── YGGravity.m ├── YGGravityImageView.h └── YGGravityImageView.m └── example ├── zhonggantest.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── wangdan.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── zhangkaifeng.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── wangdan.xcuserdatad │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── zhonggantest.xcscheme │ └── zhangkaifeng.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── zhonggantest.xcscheme └── zhonggantest ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m ├── YGGravityImageView ├── YGGravity.h ├── YGGravity.m ├── YGGravityImageView.h └── YGGravityImageView.m ├── login_bg6@2x.png └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /802473389dd1140ac59e2e8dc29518fc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zkfpk6/YGGrivityImageView/c1d3fd1de0166596a9fe566dca3cae07a797c95d/802473389dd1140ac59e2e8dc29518fc.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![image](https://github.com/zkfpk6/YGGrivityImageView/blob/master/802473389dd1140ac59e2e8dc29518fc.gif) 3 | 4 | 5 | 6 | # YGGrivityImageView 7 | 重力感应imageView/A grivity ImageView 8 | 可以重力感应控制imageView左右滑动的控件,使用方法简单四步: 9 | 10 | YGGravityImageView *imageView = [[YGGravityImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 11 | imageView.image = [UIImage imageNamed:@"login_bg6.png"]; 12 | [self.view addSubview:imageView]; 13 | [imageView startAnimate]; 14 | 15 | 觉得好用的话请给个star哦 16 | 17 | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 18 | 19 | Can slide around accelerometer control imageView controls, using simple 4 steps: 20 | 21 | YGGravityImageView *imageView = [[YGGravityImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 22 | imageView.image = [UIImage imageNamed:@"login_bg6.png"]; 23 | [self.view addSubview:imageView]; 24 | [imageView startAnimate]; 25 | 26 | If you feel good, please give me a star 27 | -------------------------------------------------------------------------------- /YGGrivityImageView/YGGravityImageView/YGGravity.h: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravity.h 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface YGGravity : NSObject 13 | @property(nonatomic,strong)CMMotionManager *manager; 14 | 15 | /** 16 | * 时间间隔 17 | */ 18 | @property (nonatomic,assign) float timeInterval; 19 | 20 | /** 21 | * 单例创建方法 22 | * 23 | * @return 单例 24 | */ 25 | + (YGGravity *)sharedGravity; 26 | 27 | /** 28 | * 开始重力加速度 29 | * 30 | * @param completeBlock 重力加速度block,返回xyz 31 | */ 32 | -(void)startAccelerometerUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 33 | 34 | /** 35 | * 开始重力感应 36 | * 37 | * @param completeBlock 重力感应block,返回xyz 38 | */ 39 | -(void)startGyroUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 40 | 41 | /** 42 | * 开始陀螺仪 43 | * 44 | * @param completeBlock 陀螺仪block,返回xyz 45 | */ 46 | -(void)startDeviceMotionUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 47 | 48 | /** 49 | * 停止 50 | */ 51 | -(void)stop; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /YGGrivityImageView/YGGravityImageView/YGGravity.m: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravity.m 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "YGGravity.h" 10 | 11 | @implementation YGGravity 12 | { 13 | NSOperationQueue *_queue; 14 | void(^_completeBlockGyro)(float x,float y,float z); 15 | void(^_completeBlockAccelerometer)(float x,float y,float z); 16 | void(^_completeBlockDeviceMotion)(float x,float y,float z); 17 | } 18 | - (instancetype)init 19 | { 20 | self = [super init]; 21 | if (self) 22 | { 23 | [self configGravity]; 24 | } 25 | return self; 26 | } 27 | 28 | -(void)configGravity 29 | { 30 | _manager = [[CMMotionManager alloc] init]; 31 | //添加一个队列线程 32 | _queue = [[NSOperationQueue alloc] init]; 33 | } 34 | 35 | -(void)startGyroUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 36 | { 37 | //重力感应 38 | if (_manager.gyroAvailable) 39 | { 40 | //更新速度 41 | _manager.gyroUpdateInterval = _timeInterval; 42 | //block 43 | [_manager startGyroUpdatesToQueue:_queue withHandler:^(CMGyroData *gyroData, NSError *error) 44 | { 45 | if (error) 46 | { 47 | //停止重力感应更新 48 | [_manager stopGyroUpdates]; 49 | NSLog(@"%@",[NSString stringWithFormat:@"gryerror:%@",error]); 50 | } 51 | else 52 | { 53 | _completeBlockGyro = completeBlock; 54 | //回主线程 55 | [self performSelectorOnMainThread:@selector(gyroUpdate:) withObject:gyroData waitUntilDone:NO]; 56 | } 57 | }]; 58 | } 59 | else 60 | { 61 | NSLog(@"设备没有重力感应"); 62 | } 63 | } 64 | 65 | -(void)startAccelerometerUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 66 | { 67 | //加速度 68 | if (_manager.accelerometerAvailable) 69 | { 70 | //更新速度 71 | _manager.accelerometerUpdateInterval = _timeInterval; 72 | //block 73 | [_manager startAccelerometerUpdatesToQueue:_queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) 74 | { 75 | _completeBlockAccelerometer = completeBlock; 76 | if (error) 77 | { 78 | [_manager stopAccelerometerUpdates]; 79 | NSLog(@"%@",error.localizedDescription); 80 | } 81 | else 82 | { 83 | [self performSelectorOnMainThread:@selector(accelerometerUpdate:) withObject:accelerometerData waitUntilDone:NO]; 84 | } 85 | }]; 86 | } 87 | else 88 | { 89 | NSLog(@"设备没有加速器"); 90 | } 91 | } 92 | 93 | -(void)startDeviceMotionUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 94 | { 95 | //判断有无陀螺仪 96 | if (_manager.deviceMotionAvailable) 97 | { 98 | //更新 99 | _manager.deviceMotionUpdateInterval = _timeInterval; 100 | //block 101 | [_manager startDeviceMotionUpdatesToQueue:_queue withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) { 102 | _completeBlockDeviceMotion = completeBlock; 103 | if (error) 104 | { 105 | [_manager stopAccelerometerUpdates]; 106 | NSLog(@"%@",error.localizedDescription); 107 | } 108 | else 109 | { 110 | [self performSelectorOnMainThread:@selector(deviceMotionUpdate:) withObject:motion waitUntilDone:NO]; 111 | } 112 | }]; 113 | } 114 | else 115 | { 116 | NSLog(@"设备没有陀螺仪"); 117 | } 118 | } 119 | 120 | -(void)gyroUpdate:(CMGyroData *)gyroData; 121 | { 122 | //分量 123 | _completeBlockGyro(gyroData.rotationRate.x,gyroData.rotationRate.y,gyroData.rotationRate.z); 124 | } 125 | 126 | -(void)accelerometerUpdate:(CMAccelerometerData *)accelerometerData; 127 | { 128 | //重力加速度三维分量 129 | _completeBlockAccelerometer(accelerometerData.acceleration.x,accelerometerData.acceleration.y,accelerometerData.acceleration.z); 130 | } 131 | 132 | -(void)deviceMotionUpdate:(CMDeviceMotion *)motionData 133 | { 134 | //陀螺仪 135 | _completeBlockDeviceMotion(motionData.rotationRate.x,motionData.rotationRate.y,motionData.rotationRate.z); 136 | } 137 | 138 | -(void)stop 139 | { 140 | [_manager stopAccelerometerUpdates]; 141 | [_manager stopGyroUpdates]; 142 | [_manager stopDeviceMotionUpdates]; 143 | } 144 | 145 | 146 | + (YGGravity *)sharedGravity 147 | { 148 | static YGGravity *gravity = nil; 149 | static dispatch_once_t predicate; 150 | dispatch_once(&predicate, ^{ 151 | gravity = [[self alloc] init]; 152 | }); 153 | return gravity; 154 | } 155 | 156 | @end 157 | -------------------------------------------------------------------------------- /YGGrivityImageView/YGGravityImageView/YGGravityImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravityImageView.h 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/23. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YGGravityImageView : UIView 12 | 13 | /** 14 | * 显示的图片 15 | */ 16 | @property (nonatomic,strong) UIImage *image; 17 | @property (nonatomic,strong,readonly) UIImageView * myImageView; 18 | 19 | /** 20 | * 开始重力感应 21 | */ 22 | -(void)startAnimate; 23 | 24 | /** 25 | * 停止重力感应 26 | */ 27 | -(void)stopAnimate; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /YGGrivityImageView/YGGravityImageView/YGGravityImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravityImageView.m 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/23. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "YGGravityImageView.h" 10 | #import "YGGravity.h" 11 | 12 | #define SPEED 50 13 | 14 | @implementation YGGravityImageView 15 | 16 | 17 | - (instancetype)initWithFrame:(CGRect)frame 18 | { 19 | self = [super initWithFrame:frame]; 20 | if (self) 21 | { 22 | [self configUI]; 23 | } 24 | return self; 25 | } 26 | 27 | -(void)configUI 28 | { 29 | _myImageView = [[UIImageView alloc]init]; 30 | [self addSubview:_myImageView]; 31 | } 32 | 33 | -(void)setImage:(UIImage *)image 34 | { 35 | _image = image; 36 | _myImageView.image = image; 37 | [_myImageView sizeToFit]; 38 | _myImageView.frame = CGRectMake(0, 0, self.frame.size.height *(_myImageView.frame.size.width / _myImageView.frame.size.height), self.frame.size.height); 39 | _myImageView.center = CGPointMake(self.frame.size.width/2,self.frame.size.height/2); 40 | } 41 | 42 | -(void)startAnimate 43 | { 44 | float scrollSpeed = (_myImageView.frame.size.width - self.frame.size.width)/2/SPEED; 45 | 46 | //注意:此处时间间隔如果给0.01 iOS8下由于未知原因弹出键盘会导致cpu消耗大于100% 47 | [YGGravity sharedGravity].timeInterval = 0.02; 48 | [[YGGravity sharedGravity]startDeviceMotionUpdatesBlock:^(float x, float y, float z) { 49 | 50 | [UIView animateKeyframesWithDuration:0.3 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeDiscrete animations:^{ 51 | 52 | if (_myImageView.frame.origin.x <=0 && _myImageView.frame.origin.x >= self.frame.size.width - _myImageView.frame.size.width) 53 | { 54 | float invertedYRotationRate = y * -1.0; 55 | 56 | float interpretedXOffset = _myImageView.frame.origin.x + invertedYRotationRate * (_myImageView.frame.size.width/[UIScreen mainScreen].bounds.size.width) * scrollSpeed + _myImageView.frame.size.width/2; 57 | 58 | _myImageView.center = CGPointMake(interpretedXOffset, _myImageView.center.y); 59 | } 60 | 61 | if (_myImageView.frame.origin.x >0) 62 | { 63 | _myImageView.frame = CGRectMake(0, _myImageView.frame.origin.y, _myImageView.frame.size.width, _myImageView.frame.size.height); 64 | } 65 | if (_myImageView.frame.origin.x < self.frame.size.width - _myImageView.frame.size.width) 66 | { 67 | _myImageView.frame = CGRectMake(self.frame.size.width - _myImageView.frame.size.width, _myImageView.frame.origin.y, _myImageView.frame.size.width, _myImageView.frame.size.height); 68 | } 69 | } completion:nil]; 70 | 71 | 72 | }]; 73 | } 74 | 75 | -(void)stopAnimate 76 | { 77 | [[YGGravity sharedGravity] stop]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 529B622A1D1A3577008C40A6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 529B62291D1A3577008C40A6 /* main.m */; }; 11 | 529B622D1D1A3577008C40A6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 529B622C1D1A3577008C40A6 /* AppDelegate.m */; }; 12 | 529B62301D1A3577008C40A6 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 529B622F1D1A3577008C40A6 /* ViewController.m */; }; 13 | 529B62351D1A3577008C40A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 529B62341D1A3577008C40A6 /* Assets.xcassets */; }; 14 | 529B62381D1A3577008C40A6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 529B62361D1A3577008C40A6 /* LaunchScreen.storyboard */; }; 15 | 529B62401D1A3680008C40A6 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 529B623F1D1A3680008C40A6 /* CoreMotion.framework */; }; 16 | F97E9AB21D1BB3F700E6F6A7 /* login_bg6@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F97E9AB11D1BB3F700E6F6A7 /* login_bg6@2x.png */; }; 17 | F9A9B1621D211A9C00D7054B /* YGGravity.m in Sources */ = {isa = PBXBuildFile; fileRef = F9A9B15F1D211A9C00D7054B /* YGGravity.m */; }; 18 | F9A9B1631D211A9C00D7054B /* YGGravityImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = F9A9B1611D211A9C00D7054B /* YGGravityImageView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 529B62251D1A3577008C40A6 /* zhonggantest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = zhonggantest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 529B62291D1A3577008C40A6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | 529B622B1D1A3577008C40A6 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 529B622C1D1A3577008C40A6 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 529B622E1D1A3577008C40A6 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 529B622F1D1A3577008C40A6 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 529B62341D1A3577008C40A6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 529B62371D1A3577008C40A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 30 | 529B62391D1A3577008C40A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 529B623F1D1A3680008C40A6 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; }; 32 | F97E9AB11D1BB3F700E6F6A7 /* login_bg6@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "login_bg6@2x.png"; sourceTree = ""; }; 33 | F9A9B15E1D211A9C00D7054B /* YGGravity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGGravity.h; sourceTree = ""; }; 34 | F9A9B15F1D211A9C00D7054B /* YGGravity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YGGravity.m; sourceTree = ""; }; 35 | F9A9B1601D211A9C00D7054B /* YGGravityImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGGravityImageView.h; sourceTree = ""; }; 36 | F9A9B1611D211A9C00D7054B /* YGGravityImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YGGravityImageView.m; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | 529B62221D1A3577008C40A6 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | 529B62401D1A3680008C40A6 /* CoreMotion.framework in Frameworks */, 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 529B621C1D1A3577008C40A6 = { 52 | isa = PBXGroup; 53 | children = ( 54 | 529B623F1D1A3680008C40A6 /* CoreMotion.framework */, 55 | 529B62271D1A3577008C40A6 /* zhonggantest */, 56 | 529B62261D1A3577008C40A6 /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 529B62261D1A3577008C40A6 /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 529B62251D1A3577008C40A6 /* zhonggantest.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 529B62271D1A3577008C40A6 /* zhonggantest */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | F9A9B15D1D211A9C00D7054B /* YGGravityImageView */, 72 | 529B622B1D1A3577008C40A6 /* AppDelegate.h */, 73 | 529B622C1D1A3577008C40A6 /* AppDelegate.m */, 74 | 529B622E1D1A3577008C40A6 /* ViewController.h */, 75 | 529B622F1D1A3577008C40A6 /* ViewController.m */, 76 | 529B62341D1A3577008C40A6 /* Assets.xcassets */, 77 | 529B62361D1A3577008C40A6 /* LaunchScreen.storyboard */, 78 | 529B62391D1A3577008C40A6 /* Info.plist */, 79 | 529B62281D1A3577008C40A6 /* Supporting Files */, 80 | F97E9AB11D1BB3F700E6F6A7 /* login_bg6@2x.png */, 81 | ); 82 | path = zhonggantest; 83 | sourceTree = ""; 84 | }; 85 | 529B62281D1A3577008C40A6 /* Supporting Files */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 529B62291D1A3577008C40A6 /* main.m */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | F9A9B15D1D211A9C00D7054B /* YGGravityImageView */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | F9A9B15E1D211A9C00D7054B /* YGGravity.h */, 97 | F9A9B15F1D211A9C00D7054B /* YGGravity.m */, 98 | F9A9B1601D211A9C00D7054B /* YGGravityImageView.h */, 99 | F9A9B1611D211A9C00D7054B /* YGGravityImageView.m */, 100 | ); 101 | path = YGGravityImageView; 102 | sourceTree = ""; 103 | }; 104 | /* End PBXGroup section */ 105 | 106 | /* Begin PBXNativeTarget section */ 107 | 529B62241D1A3577008C40A6 /* zhonggantest */ = { 108 | isa = PBXNativeTarget; 109 | buildConfigurationList = 529B623C1D1A3577008C40A6 /* Build configuration list for PBXNativeTarget "zhonggantest" */; 110 | buildPhases = ( 111 | 529B62211D1A3577008C40A6 /* Sources */, 112 | 529B62221D1A3577008C40A6 /* Frameworks */, 113 | 529B62231D1A3577008C40A6 /* Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = zhonggantest; 120 | productName = zhonggantest; 121 | productReference = 529B62251D1A3577008C40A6 /* zhonggantest.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 529B621D1D1A3577008C40A6 /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastUpgradeCheck = 0730; 131 | ORGANIZATIONNAME = "王丹"; 132 | TargetAttributes = { 133 | 529B62241D1A3577008C40A6 = { 134 | CreatedOnToolsVersion = 7.3.1; 135 | DevelopmentTeam = 53V8GBAUR6; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 529B62201D1A3577008C40A6 /* Build configuration list for PBXProject "zhonggantest" */; 140 | compatibilityVersion = "Xcode 3.2"; 141 | developmentRegion = English; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 529B621C1D1A3577008C40A6; 148 | productRefGroup = 529B62261D1A3577008C40A6 /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 529B62241D1A3577008C40A6 /* zhonggantest */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 529B62231D1A3577008C40A6 /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | F97E9AB21D1BB3F700E6F6A7 /* login_bg6@2x.png in Resources */, 163 | 529B62381D1A3577008C40A6 /* LaunchScreen.storyboard in Resources */, 164 | 529B62351D1A3577008C40A6 /* Assets.xcassets in Resources */, 165 | ); 166 | runOnlyForDeploymentPostprocessing = 0; 167 | }; 168 | /* End PBXResourcesBuildPhase section */ 169 | 170 | /* Begin PBXSourcesBuildPhase section */ 171 | 529B62211D1A3577008C40A6 /* Sources */ = { 172 | isa = PBXSourcesBuildPhase; 173 | buildActionMask = 2147483647; 174 | files = ( 175 | F9A9B1621D211A9C00D7054B /* YGGravity.m in Sources */, 176 | 529B62301D1A3577008C40A6 /* ViewController.m in Sources */, 177 | 529B622D1D1A3577008C40A6 /* AppDelegate.m in Sources */, 178 | F9A9B1631D211A9C00D7054B /* YGGravityImageView.m in Sources */, 179 | 529B622A1D1A3577008C40A6 /* main.m in Sources */, 180 | ); 181 | runOnlyForDeploymentPostprocessing = 0; 182 | }; 183 | /* End PBXSourcesBuildPhase section */ 184 | 185 | /* Begin PBXVariantGroup section */ 186 | 529B62361D1A3577008C40A6 /* LaunchScreen.storyboard */ = { 187 | isa = PBXVariantGroup; 188 | children = ( 189 | 529B62371D1A3577008C40A6 /* Base */, 190 | ); 191 | name = LaunchScreen.storyboard; 192 | sourceTree = ""; 193 | }; 194 | /* End PBXVariantGroup section */ 195 | 196 | /* Begin XCBuildConfiguration section */ 197 | 529B623A1D1A3577008C40A6 /* Debug */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_ANALYZER_NONNULL = YES; 202 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 203 | CLANG_CXX_LIBRARY = "libc++"; 204 | CLANG_ENABLE_MODULES = YES; 205 | CLANG_ENABLE_OBJC_ARC = YES; 206 | CLANG_WARN_BOOL_CONVERSION = YES; 207 | CLANG_WARN_CONSTANT_CONVERSION = YES; 208 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 209 | CLANG_WARN_EMPTY_BODY = YES; 210 | CLANG_WARN_ENUM_CONVERSION = YES; 211 | CLANG_WARN_INT_CONVERSION = YES; 212 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 213 | CLANG_WARN_UNREACHABLE_CODE = YES; 214 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 215 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 216 | COPY_PHASE_STRIP = NO; 217 | DEBUG_INFORMATION_FORMAT = dwarf; 218 | ENABLE_STRICT_OBJC_MSGSEND = YES; 219 | ENABLE_TESTABILITY = YES; 220 | GCC_C_LANGUAGE_STANDARD = gnu99; 221 | GCC_DYNAMIC_NO_PIC = NO; 222 | GCC_NO_COMMON_BLOCKS = YES; 223 | GCC_OPTIMIZATION_LEVEL = 0; 224 | GCC_PREPROCESSOR_DEFINITIONS = ( 225 | "DEBUG=1", 226 | "$(inherited)", 227 | ); 228 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 229 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 230 | GCC_WARN_UNDECLARED_SELECTOR = YES; 231 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 232 | GCC_WARN_UNUSED_FUNCTION = YES; 233 | GCC_WARN_UNUSED_VARIABLE = YES; 234 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 235 | MTL_ENABLE_DEBUG_INFO = YES; 236 | ONLY_ACTIVE_ARCH = YES; 237 | SDKROOT = iphoneos; 238 | }; 239 | name = Debug; 240 | }; 241 | 529B623B1D1A3577008C40A6 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 247 | CLANG_CXX_LIBRARY = "libc++"; 248 | CLANG_ENABLE_MODULES = YES; 249 | CLANG_ENABLE_OBJC_ARC = YES; 250 | CLANG_WARN_BOOL_CONVERSION = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_UNREACHABLE_CODE = YES; 258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 259 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 260 | COPY_PHASE_STRIP = NO; 261 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 262 | ENABLE_NS_ASSERTIONS = NO; 263 | ENABLE_STRICT_OBJC_MSGSEND = YES; 264 | GCC_C_LANGUAGE_STANDARD = gnu99; 265 | GCC_NO_COMMON_BLOCKS = YES; 266 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 267 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 268 | GCC_WARN_UNDECLARED_SELECTOR = YES; 269 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 270 | GCC_WARN_UNUSED_FUNCTION = YES; 271 | GCC_WARN_UNUSED_VARIABLE = YES; 272 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 273 | MTL_ENABLE_DEBUG_INFO = NO; 274 | SDKROOT = iphoneos; 275 | VALIDATE_PRODUCT = YES; 276 | }; 277 | name = Release; 278 | }; 279 | 529B623D1D1A3577008C40A6 /* Debug */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 283 | CODE_SIGN_IDENTITY = "iPhone Developer"; 284 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 285 | INFOPLIST_FILE = zhonggantest/Info.plist; 286 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 287 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 288 | PRODUCT_BUNDLE_IDENTIFIER = yogee.cn.zhonggantest; 289 | PRODUCT_NAME = "$(TARGET_NAME)"; 290 | PROVISIONING_PROFILE = ""; 291 | }; 292 | name = Debug; 293 | }; 294 | 529B623E1D1A3577008C40A6 /* Release */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | CODE_SIGN_IDENTITY = "iPhone Developer"; 299 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 300 | INFOPLIST_FILE = zhonggantest/Info.plist; 301 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 302 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 303 | PRODUCT_BUNDLE_IDENTIFIER = yogee.cn.zhonggantest; 304 | PRODUCT_NAME = "$(TARGET_NAME)"; 305 | PROVISIONING_PROFILE = ""; 306 | }; 307 | name = Release; 308 | }; 309 | /* End XCBuildConfiguration section */ 310 | 311 | /* Begin XCConfigurationList section */ 312 | 529B62201D1A3577008C40A6 /* Build configuration list for PBXProject "zhonggantest" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | 529B623A1D1A3577008C40A6 /* Debug */, 316 | 529B623B1D1A3577008C40A6 /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | defaultConfigurationName = Release; 320 | }; 321 | 529B623C1D1A3577008C40A6 /* Build configuration list for PBXNativeTarget "zhonggantest" */ = { 322 | isa = XCConfigurationList; 323 | buildConfigurations = ( 324 | 529B623D1D1A3577008C40A6 /* Debug */, 325 | 529B623E1D1A3577008C40A6 /* Release */, 326 | ); 327 | defaultConfigurationIsVisible = 0; 328 | defaultConfigurationName = Release; 329 | }; 330 | /* End XCConfigurationList section */ 331 | }; 332 | rootObject = 529B621D1D1A3577008C40A6 /* Project object */; 333 | } 334 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/project.xcworkspace/xcuserdata/wangdan.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zkfpk6/YGGrivityImageView/c1d3fd1de0166596a9fe566dca3cae07a797c95d/YGGrivityImageView/example/zhonggantest.xcodeproj/project.xcworkspace/xcuserdata/wangdan.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/project.xcworkspace/xcuserdata/zhangkaifeng.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zkfpk6/YGGrivityImageView/c1d3fd1de0166596a9fe566dca3cae07a797c95d/YGGrivityImageView/example/zhonggantest.xcodeproj/project.xcworkspace/xcuserdata/zhangkaifeng.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/xcuserdata/wangdan.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | zhonggantest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 529B62241D1A3577008C40A6 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/xcuserdata/wangdan.xcuserdatad/xcschemes/zhonggantest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/xcuserdata/zhangkaifeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/xcuserdata/zhangkaifeng.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | zhonggantest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 529B62241D1A3577008C40A6 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest.xcodeproj/xcuserdata/zhangkaifeng.xcuserdatad/xcschemes/zhonggantest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 78 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // zhonggantest 4 | // 5 | // Created by 张楷枫 on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // zhonggantest 4 | // 5 | // Created by 张楷枫 on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; 21 | [_window makeKeyAndVisible]; 22 | ViewController *vc = [[ViewController alloc]init]; 23 | self.window.rootViewController = vc; 24 | return YES; 25 | } 26 | 27 | - (void)applicationWillResignActive:(UIApplication *)application { 28 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 29 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 30 | } 31 | 32 | - (void)applicationDidEnterBackground:(UIApplication *)application { 33 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 34 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application { 38 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 39 | } 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | - (void)applicationWillTerminate:(UIApplication *)application { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // zhonggantest 4 | // 5 | // Created by 张楷枫 on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface ViewController : UIViewController 13 | 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // zhonggantest 4 | // 5 | // Created by 张楷枫 on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "YGGravity.h" 11 | #import "YGGravityImageView.h" 12 | 13 | @interface ViewController () 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | YGGravityImageView *imageView = [[YGGravityImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 23 | imageView.image = [UIImage imageNamed:@"login_bg6.png"]; 24 | [self.view addSubview:imageView]; 25 | 26 | [imageView startAnimate]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/YGGravityImageView/YGGravity.h: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravity.h 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface YGGravity : NSObject 13 | @property(nonatomic,strong)CMMotionManager *manager; 14 | 15 | /** 16 | * 时间间隔 17 | */ 18 | @property (nonatomic,assign) float timeInterval; 19 | 20 | /** 21 | * 单例创建方法 22 | * 23 | * @return 单例 24 | */ 25 | + (YGGravity *)sharedGravity; 26 | 27 | /** 28 | * 开始重力加速度 29 | * 30 | * @param completeBlock 重力加速度block,返回xyz 31 | */ 32 | -(void)startAccelerometerUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 33 | 34 | /** 35 | * 开始重力感应 36 | * 37 | * @param completeBlock 重力感应block,返回xyz 38 | */ 39 | -(void)startGyroUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 40 | 41 | /** 42 | * 开始陀螺仪 43 | * 44 | * @param completeBlock 陀螺仪block,返回xyz 45 | */ 46 | -(void)startDeviceMotionUpdatesBlock:(void(^)(float x,float y,float z))completeBlock; 47 | 48 | /** 49 | * 停止 50 | */ 51 | -(void)stop; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/YGGravityImageView/YGGravity.m: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravity.m 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "YGGravity.h" 10 | 11 | @implementation YGGravity 12 | { 13 | NSOperationQueue *_queue; 14 | void(^_completeBlockGyro)(float x,float y,float z); 15 | void(^_completeBlockAccelerometer)(float x,float y,float z); 16 | void(^_completeBlockDeviceMotion)(float x,float y,float z); 17 | } 18 | - (instancetype)init 19 | { 20 | self = [super init]; 21 | if (self) 22 | { 23 | [self configGravity]; 24 | } 25 | return self; 26 | } 27 | 28 | -(void)configGravity 29 | { 30 | _manager = [[CMMotionManager alloc] init]; 31 | //添加一个队列线程 32 | _queue = [[NSOperationQueue alloc] init]; 33 | } 34 | 35 | -(void)startGyroUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 36 | { 37 | //重力感应 38 | if (_manager.gyroAvailable) 39 | { 40 | //更新速度 41 | _manager.gyroUpdateInterval = _timeInterval; 42 | //block 43 | [_manager startGyroUpdatesToQueue:_queue withHandler:^(CMGyroData *gyroData, NSError *error) 44 | { 45 | if (error) 46 | { 47 | //停止重力感应更新 48 | [_manager stopGyroUpdates]; 49 | NSLog(@"%@",[NSString stringWithFormat:@"gryerror:%@",error]); 50 | } 51 | else 52 | { 53 | _completeBlockGyro = completeBlock; 54 | //回主线程 55 | [self performSelectorOnMainThread:@selector(gyroUpdate:) withObject:gyroData waitUntilDone:NO]; 56 | } 57 | }]; 58 | } 59 | else 60 | { 61 | NSLog(@"设备没有重力感应"); 62 | } 63 | } 64 | 65 | -(void)startAccelerometerUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 66 | { 67 | //加速度 68 | if (_manager.accelerometerAvailable) 69 | { 70 | //更新速度 71 | _manager.accelerometerUpdateInterval = _timeInterval; 72 | //block 73 | [_manager startAccelerometerUpdatesToQueue:_queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) 74 | { 75 | _completeBlockAccelerometer = completeBlock; 76 | if (error) 77 | { 78 | [_manager stopAccelerometerUpdates]; 79 | NSLog(@"%@",error.localizedDescription); 80 | } 81 | else 82 | { 83 | [self performSelectorOnMainThread:@selector(accelerometerUpdate:) withObject:accelerometerData waitUntilDone:NO]; 84 | } 85 | }]; 86 | } 87 | else 88 | { 89 | NSLog(@"设备没有加速器"); 90 | } 91 | } 92 | 93 | -(void)startDeviceMotionUpdatesBlock:(void(^)(float x,float y,float z))completeBlock 94 | { 95 | //判断有无陀螺仪 96 | if (_manager.deviceMotionAvailable) 97 | { 98 | //更新 99 | _manager.deviceMotionUpdateInterval = _timeInterval; 100 | //block 101 | [_manager startDeviceMotionUpdatesToQueue:_queue withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) { 102 | _completeBlockDeviceMotion = completeBlock; 103 | if (error) 104 | { 105 | [_manager stopAccelerometerUpdates]; 106 | NSLog(@"%@",error.localizedDescription); 107 | } 108 | else 109 | { 110 | [self performSelectorOnMainThread:@selector(deviceMotionUpdate:) withObject:motion waitUntilDone:NO]; 111 | } 112 | }]; 113 | } 114 | else 115 | { 116 | NSLog(@"设备没有陀螺仪"); 117 | } 118 | } 119 | 120 | -(void)gyroUpdate:(CMGyroData *)gyroData; 121 | { 122 | //分量 123 | _completeBlockGyro(gyroData.rotationRate.x,gyroData.rotationRate.y,gyroData.rotationRate.z); 124 | } 125 | 126 | -(void)accelerometerUpdate:(CMAccelerometerData *)accelerometerData; 127 | { 128 | //重力加速度三维分量 129 | _completeBlockAccelerometer(accelerometerData.acceleration.x,accelerometerData.acceleration.y,accelerometerData.acceleration.z); 130 | } 131 | 132 | -(void)deviceMotionUpdate:(CMDeviceMotion *)motionData 133 | { 134 | //陀螺仪 135 | _completeBlockDeviceMotion(motionData.rotationRate.x,motionData.rotationRate.y,motionData.rotationRate.z); 136 | } 137 | 138 | -(void)stop 139 | { 140 | [_manager stopAccelerometerUpdates]; 141 | [_manager stopGyroUpdates]; 142 | [_manager stopDeviceMotionUpdates]; 143 | } 144 | 145 | 146 | + (YGGravity *)sharedGravity 147 | { 148 | static YGGravity *gravity = nil; 149 | static dispatch_once_t predicate; 150 | dispatch_once(&predicate, ^{ 151 | gravity = [[self alloc] init]; 152 | }); 153 | return gravity; 154 | } 155 | 156 | @end 157 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/YGGravityImageView/YGGravityImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravityImageView.h 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/23. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YGGravityImageView : UIView 12 | 13 | /** 14 | * 显示的图片 15 | */ 16 | @property (nonatomic,strong) UIImage *image; 17 | @property (nonatomic,strong,readonly) UIImageView * myImageView; 18 | 19 | /** 20 | * 开始重力感应 21 | */ 22 | -(void)startAnimate; 23 | 24 | /** 25 | * 停止重力感应 26 | */ 27 | -(void)stopAnimate; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/YGGravityImageView/YGGravityImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YGGravityImageView.m 3 | // zhonggantest 4 | // 5 | // Created by zhangkaifeng on 16/6/23. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import "YGGravityImageView.h" 10 | #import "YGGravity.h" 11 | 12 | #define SPEED 50 13 | 14 | @implementation YGGravityImageView 15 | 16 | 17 | - (instancetype)initWithFrame:(CGRect)frame 18 | { 19 | self = [super initWithFrame:frame]; 20 | if (self) 21 | { 22 | [self configUI]; 23 | } 24 | return self; 25 | } 26 | 27 | -(void)configUI 28 | { 29 | _myImageView = [[UIImageView alloc]init]; 30 | [self addSubview:_myImageView]; 31 | } 32 | 33 | -(void)setImage:(UIImage *)image 34 | { 35 | _image = image; 36 | _myImageView.image = image; 37 | [_myImageView sizeToFit]; 38 | _myImageView.frame = CGRectMake(0, 0, self.frame.size.height *(_myImageView.frame.size.width / _myImageView.frame.size.height), self.frame.size.height); 39 | _myImageView.center = CGPointMake(self.frame.size.width/2,self.frame.size.height/2); 40 | } 41 | 42 | -(void)startAnimate 43 | { 44 | float scrollSpeed = (_myImageView.frame.size.width - self.frame.size.width)/2/SPEED; 45 | 46 | //注意:此处时间间隔如果给0.01 iOS8下由于未知原因弹出键盘会导致cpu消耗大于100% 47 | [YGGravity sharedGravity].timeInterval = 0.02; 48 | [[YGGravity sharedGravity]startDeviceMotionUpdatesBlock:^(float x, float y, float z) { 49 | 50 | [UIView animateKeyframesWithDuration:0.3 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeDiscrete animations:^{ 51 | 52 | if (_myImageView.frame.origin.x <=0 && _myImageView.frame.origin.x >= self.frame.size.width - _myImageView.frame.size.width) 53 | { 54 | float invertedYRotationRate = y * -1.0; 55 | 56 | float interpretedXOffset = _myImageView.frame.origin.x + invertedYRotationRate * (_myImageView.frame.size.width/[UIScreen mainScreen].bounds.size.width) * scrollSpeed + _myImageView.frame.size.width/2; 57 | 58 | _myImageView.center = CGPointMake(interpretedXOffset, _myImageView.center.y); 59 | } 60 | 61 | if (_myImageView.frame.origin.x >0) 62 | { 63 | _myImageView.frame = CGRectMake(0, _myImageView.frame.origin.y, _myImageView.frame.size.width, _myImageView.frame.size.height); 64 | } 65 | if (_myImageView.frame.origin.x < self.frame.size.width - _myImageView.frame.size.width) 66 | { 67 | _myImageView.frame = CGRectMake(self.frame.size.width - _myImageView.frame.size.width, _myImageView.frame.origin.y, _myImageView.frame.size.width, _myImageView.frame.size.height); 68 | } 69 | } completion:nil]; 70 | 71 | 72 | }]; 73 | } 74 | 75 | -(void)stopAnimate 76 | { 77 | [[YGGravity sharedGravity] stop]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/login_bg6@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zkfpk6/YGGrivityImageView/c1d3fd1de0166596a9fe566dca3cae07a797c95d/YGGrivityImageView/example/zhonggantest/login_bg6@2x.png -------------------------------------------------------------------------------- /YGGrivityImageView/example/zhonggantest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // zhonggantest 4 | // 5 | // Created by 张楷枫 on 16/6/22. 6 | // Copyright © 2016年 张楷枫. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------