├── README.md ├── Default-568h@2x.png ├── MCCatchRedPacket ├── img │ ├── bird.gif │ ├── ic_arrow.png │ ├── btn_catch.png │ ├── ic_circle.png │ ├── btn_catch_normal.png │ ├── ic_circle_normal.png │ └── btn_close_normal@2x.png ├── ViewController.h ├── YLGIFImage │ ├── YLImageView.h │ ├── YLGIFImage.h │ ├── YLImageView.m │ └── YLGIFImage.m ├── AppDelegate.h ├── MCcatchView │ ├── RedPacketView.h │ ├── RedPacketView.m │ ├── MCCatchView.h │ ├── YGGravity.h │ ├── YGGravity.m │ └── MCCatchView.m ├── main.m ├── MCCatchRedPacketController.h ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.m ├── AppDelegate.m └── MCCatchRedPacketController.m ├── MCCatchRedPacket.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── MC.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcuserdata │ └── MC.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── MCCatchRedPacket.xcscheme └── project.pbxproj ├── MCCatchRedPacketTests ├── Info.plist └── MCCatchRedPacketTests.m └── MCCatchRedPacketUITests ├── Info.plist └── MCCatchRedPacketUITests.m /README.md: -------------------------------------------------------------------------------- 1 | # MCCatchRedPacket 2 | 低仿uc捉红包功能 3 | -------------------------------------------------------------------------------- /Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/Default-568h@2x.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/bird.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/bird.gif -------------------------------------------------------------------------------- /MCCatchRedPacket/img/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/ic_arrow.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/btn_catch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/btn_catch.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/ic_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/ic_circle.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/btn_catch_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/btn_catch_normal.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/ic_circle_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/ic_circle_normal.png -------------------------------------------------------------------------------- /MCCatchRedPacket/img/btn_close_normal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket/img/btn_close_normal@2x.png -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/project.xcworkspace/xcuserdata/MC.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michanMC/MCCatchRedPacket/HEAD/MCCatchRedPacket.xcodeproj/project.xcworkspace/xcuserdata/MC.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /MCCatchRedPacket/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "MCCatchView.h" 10 | #import 11 | 12 | @interface ViewController : UIViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /MCCatchRedPacket/YLGIFImage/YLImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // YLImageView.h 3 | // YLGIFImage 4 | // 5 | // Created by Yong Li on 14-3-2. 6 | // Copyright (c) 2014年 Yong Li. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YLImageView : UIImageView 12 | 13 | @property (nonatomic, copy) NSString *runLoopMode; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MCCatchRedPacket/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/RedPacketView.h: -------------------------------------------------------------------------------- 1 | // 2 | // RedPacketView.h 3 | // MCscenekit 4 | // 5 | // Created by MC on 16/10/27. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "YLImageView.h" 10 | #import 11 | 12 | @interface RedPacketView : YLImageView 13 | @property (nonatomic, assign) NSInteger state_size; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MCCatchRedPacket/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. 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 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCCatchRedPacketController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchRedPacketController.h 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MCCatchView.h" 11 | 12 | 13 | @interface MCCatchRedPacketController : UIViewController 14 | 15 | @property(nonatomic,weak)iddelegate; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/xcuserdata/MC.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/RedPacketView.m: -------------------------------------------------------------------------------- 1 | // 2 | // RedPacketView.m 3 | // MCscenekit 4 | // 5 | // Created by MC on 16/10/27. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "RedPacketView.h" 10 | 11 | @implementation RedPacketView 12 | 13 | - (id)initWithFrame:(CGRect)frame { 14 | self = [super initWithFrame:frame]; 15 | if (self) { 16 | } 17 | return self; 18 | } 19 | 20 | /* 21 | // Only override drawRect: if you perform custom drawing. 22 | // An empty implementation adversely affects performance during animation. 23 | - (void)drawRect:(CGRect)rect { 24 | // Drawing code 25 | } 26 | */ 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /MCCatchRedPacketTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MCCatchRedPacketUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/xcuserdata/MC.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MCCatchRedPacket.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 4CAC59331DC47AA800CAA825 16 | 17 | primary 18 | 19 | 20 | 4CAC594C1DC47AA800CAA825 21 | 22 | primary 23 | 24 | 25 | 4CAC59571DC47AA800CAA825 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /MCCatchRedPacket/YLGIFImage/YLGIFImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // YLGIFImage.h 3 | // YLGIFImage 4 | // 5 | // Created by Yong Li on 14-3-2. 6 | // Copyright (c) 2014年 Yong Li. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface YLGIFImage : UIImage 12 | 13 | ///----------------------- 14 | /// @name Image Attributes 15 | ///----------------------- 16 | 17 | /** 18 | A C array containing the frame durations. 19 | 20 | The number of frames is defined by the count of the `images` array property. 21 | */ 22 | @property (nonatomic, readonly) NSTimeInterval *frameDurations; 23 | 24 | /** 25 | Total duration of the animated image. 26 | */ 27 | @property (nonatomic, readonly) NSTimeInterval totalDuration; 28 | 29 | /** 30 | Number of loops the image can do before it stops 31 | */ 32 | @property (nonatomic, readonly) NSUInteger loopCount; 33 | 34 | - (UIImage*)getFrameWithIndex:(NSUInteger)idx; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /MCCatchRedPacket/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/MCCatchView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchView.h 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "RedPacketView.h" 10 | #import "YLGIFImage.h" 11 | #import 12 | 13 | @protocol MCCatchViewDelegate 14 | 15 | - (void)catchRedPacket; 16 | 17 | @end 18 | 19 | @interface MCCatchView : UIView 20 | 21 | @property (nonatomic, weak) id delegate; 22 | @property (nonatomic, strong) NSTimer *timer; 23 | /** 24 | * 显示的图片 25 | */ 26 | @property (nonatomic, strong) UIImage *image; 27 | @property (nonatomic, strong) UIView *myImageView; 28 | 29 | //飞行区域 30 | @property (nonatomic, strong) UIView *flightView; 31 | //捕捉区 32 | @property (nonatomic, strong) UIImageView *catchView; 33 | 34 | @property (nonatomic, strong) UIButton *catchBtn; 35 | - (void)prepareData:(NSArray *)array; 36 | 37 | /** 38 | * 开始重力感应 39 | */ 40 | - (void)startAnimate; 41 | 42 | /** 43 | * 停止重力感应 44 | */ 45 | - (void)stopAnimate; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /MCCatchRedPacketTests/MCCatchRedPacketTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchRedPacketTests.m 3 | // MCCatchRedPacketTests 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCCatchRedPacketTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation MCCatchRedPacketTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/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 | -------------------------------------------------------------------------------- /MCCatchRedPacketUITests/MCCatchRedPacketUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchRedPacketUITests.m 3 | // MCCatchRedPacketUITests 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MCCatchRedPacketUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation MCCatchRedPacketUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /MCCatchRedPacket/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | 获取照片,需要访问你的相机 25 | NSLocationAlwaysUsageDescription 26 | 点购商城将获取你的位置,为你提供更精准的服务 27 | NSLocationWhenInUseUsageDescription 28 | 点购商城将获取你的位置,为你提供更精准的服务 29 | NSMicrophoneUsageDescription 30 | 语音聊天服务,需要使用你的麦克风 31 | NSPhotoLibraryUsageDescription 32 | 获取图片,需要访问你的相册 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /MCCatchRedPacket/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "MCCatchRedPacketController.h" 10 | #import "RedPacketView.h" 11 | #import "ViewController.h" 12 | #import "YLGIFImage.h" 13 | 14 | @interface ViewController () { 15 | UIView *view; 16 | } 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 50)]; 25 | [btn setTitle:@"捉红包" forState:0]; 26 | [btn setTitleColor:[UIColor redColor] forState:0]; 27 | [self.view addSubview:btn]; 28 | [btn addTarget:self action:@selector(actionBtn) forControlEvents:UIControlEventTouchUpInside]; 29 | 30 | view = [[UIView alloc] initWithFrame:self.view.frame]; 31 | view.backgroundColor = [UIColor whiteColor]; 32 | RedPacketView *imgView = [[RedPacketView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; 33 | imgView.image = [YLGIFImage imageNamed:@"bird.gif"]; 34 | imgView.center = self.view.center; 35 | [view addSubview:imgView]; 36 | view.hidden = YES; 37 | [self.view addSubview:view]; 38 | 39 | // Do any additional setup after loading the view, typically from a nib. 40 | } 41 | 42 | - (void)actionBtn { 43 | MCCatchRedPacketController *ctl = [[MCCatchRedPacketController alloc] init]; 44 | ctl.delegate = self; 45 | [self presentViewController:ctl animated:YES completion:nil]; 46 | } 47 | 48 | #pragma mark - MCCatchViewDelegate 49 | - (void)catchRedPacket { 50 | view.hidden = NO; 51 | } 52 | 53 | - (void)didReceiveMemoryWarning { 54 | [super didReceiveMemoryWarning]; 55 | // Dispose of any resources that can be recreated. 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /MCCatchRedPacket/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 18 | // Override point for customization after application launch. 19 | 20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 21 | // Override point for customization after application launch. 22 | self.window.backgroundColor = [UIColor whiteColor]; 23 | 24 | //设置根视图控制器是哪个视图控制器的对象 25 | ViewController *rvc = [[ViewController alloc] init]; 26 | self.window.rootViewController = rvc; 27 | 28 | [self.window makeKeyAndVisible]; 29 | 30 | return YES; 31 | } 32 | 33 | - (void)applicationWillResignActive:(UIApplication *)application { 34 | // 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. 35 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 36 | } 37 | 38 | - (void)applicationDidEnterBackground:(UIApplication *)application { 39 | // 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. 40 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 41 | } 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 45 | } 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application { 48 | // 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. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/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 | NSOperationQueue *_queue; 13 | void (^_completeBlockGyro)(float x, float y, float z); 14 | void (^_completeBlockAccelerometer)(float x, float y, float z); 15 | void (^_completeBlockDeviceMotion)(float x, float y, float z); 16 | } 17 | 18 | - (instancetype)init { 19 | self = [super init]; 20 | if (self) { 21 | [self configGravity]; 22 | } 23 | return self; 24 | } 25 | 26 | - (void)configGravity { 27 | _manager = [[CMMotionManager alloc] init]; 28 | //添加一个队列线程 29 | _queue = [[NSOperationQueue alloc] init]; 30 | } 31 | 32 | - (void)startGyroUpdatesBlock:(void (^)(float x, float y, float z))completeBlock { 33 | //重力感应 34 | if (_manager.gyroAvailable) { 35 | //更新速度 36 | _manager.gyroUpdateInterval = _timeInterval; 37 | //block 38 | [_manager startGyroUpdatesToQueue:_queue withHandler:^(CMGyroData *gyroData, NSError *error) { 39 | if (error) { 40 | //停止重力感应更新 41 | [_manager stopGyroUpdates]; 42 | NSLog(@"%@", [NSString stringWithFormat:@"gryerror:%@", error]); 43 | } else { 44 | _completeBlockGyro = completeBlock; 45 | //回主线程 46 | [self performSelectorOnMainThread:@selector(gyroUpdate:) withObject:gyroData waitUntilDone:NO]; 47 | } 48 | }]; 49 | } else { 50 | NSLog(@"设备没有重力感应"); 51 | } 52 | } 53 | 54 | - (void)startAccelerometerUpdatesBlock:(void (^)(float x, float y, float z))completeBlock { 55 | //加速度 56 | if (_manager.accelerometerAvailable) { 57 | //更新速度 58 | _manager.accelerometerUpdateInterval = _timeInterval; 59 | //block 60 | [_manager startAccelerometerUpdatesToQueue:_queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 61 | _completeBlockAccelerometer = completeBlock; 62 | if (error) { 63 | [_manager stopAccelerometerUpdates]; 64 | NSLog(@"%@", error.localizedDescription); 65 | } else { 66 | [self performSelectorOnMainThread:@selector(accelerometerUpdate:) withObject:accelerometerData waitUntilDone:NO]; 67 | } 68 | }]; 69 | } else { 70 | NSLog(@"设备没有加速器"); 71 | } 72 | } 73 | 74 | - (void)startDeviceMotionUpdatesBlock:(void (^)(float x, float y, float z))completeBlock { 75 | //判断有无陀螺仪 76 | if (_manager.deviceMotionAvailable) { 77 | //更新 78 | _manager.deviceMotionUpdateInterval = _timeInterval; 79 | //block 80 | [_manager startDeviceMotionUpdatesToQueue:_queue withHandler:^(CMDeviceMotion *_Nullable motion, NSError *_Nullable error) { 81 | _completeBlockDeviceMotion = completeBlock; 82 | if (error) { 83 | [_manager stopAccelerometerUpdates]; 84 | NSLog(@"%@", error.localizedDescription); 85 | } else { 86 | [self performSelectorOnMainThread:@selector(deviceMotionUpdate:) withObject:motion waitUntilDone:NO]; 87 | } 88 | }]; 89 | } else { 90 | NSLog(@"设备没有陀螺仪"); 91 | } 92 | } 93 | 94 | - (void)gyroUpdate:(CMGyroData *)gyroData; 95 | { 96 | //分量 97 | _completeBlockGyro(gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z); 98 | } 99 | 100 | - (void)accelerometerUpdate:(CMAccelerometerData *)accelerometerData; 101 | { 102 | //重力加速度三维分量 103 | _completeBlockAccelerometer(accelerometerData.acceleration.x, accelerometerData.acceleration.y, accelerometerData.acceleration.z); 104 | } 105 | 106 | - (void)deviceMotionUpdate:(CMDeviceMotion *)motionData { 107 | //陀螺仪 108 | _completeBlockDeviceMotion(motionData.rotationRate.x, motionData.rotationRate.y, motionData.rotationRate.z); 109 | } 110 | 111 | - (void)stop { 112 | [_manager stopAccelerometerUpdates]; 113 | [_manager stopGyroUpdates]; 114 | [_manager stopDeviceMotionUpdates]; 115 | } 116 | 117 | + (YGGravity *)sharedGravity { 118 | static YGGravity *gravity = nil; 119 | static dispatch_once_t predicate; 120 | dispatch_once(&predicate, ^{ 121 | gravity = [[self alloc] init]; 122 | }); 123 | return gravity; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/xcuserdata/MC.xcuserdatad/xcschemes/MCCatchRedPacket.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 89 | 90 | 91 | 92 | 98 | 100 | 106 | 107 | 108 | 109 | 111 | 112 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCCatchRedPacketController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchRedPacketController.m 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "MCCatchRedPacketController.h" 10 | #import "MCCatchView.h" 11 | #import "YGGravity.h" 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | 19 | @interface MCCatchRedPacketController () { 20 | 21 | SCNVector3 forwardDirectionVector; 22 | 23 | UIView *_bgview; 24 | SCNView *_scnView; 25 | MCCatchView *imageView; 26 | } 27 | /** 28 | * AVCaptureSession对象来执行输入设备和输出设备之间的数据传递 29 | */ 30 | @property (nonatomic, strong) AVCaptureSession *session; 31 | /** 32 | * 提供来自设备的数据 33 | */ 34 | @property (nonatomic, strong) AVCaptureDeviceInput *videoInput; 35 | /** 36 | * 用于捕捉静态图片 37 | */ 38 | @property (nonatomic, strong) AVCaptureStillImageOutput *stillImageOutput; 39 | /** 40 | * 用于自动显示相机产生的实时图像,它拥有 session (outputs 被 session 所拥有) 41 | */ 42 | @property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer; 43 | 44 | @end 45 | 46 | @implementation MCCatchRedPacketController 47 | 48 | - (void)viewDidLoad { 49 | [super viewDidLoad]; 50 | [self initAVCaptureSession]; 51 | [self.session startRunning]; 52 | [self intView]; 53 | 54 | // Do any additional setup after loading the view. 55 | } 56 | 57 | - (void)intView { 58 | _bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 59 | _bgview.backgroundColor = [UIColor clearColor]; 60 | [self.view addSubview:_bgview]; 61 | 62 | [self addImgview]; 63 | 64 | UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 40 - 10, 30, 40, 40)]; 65 | [backBtn setImage:[UIImage imageNamed:@"btn_close_normal"] forState:UIControlStateNormal]; 66 | [backBtn addTarget:self action:@selector(actionBackBtn) forControlEvents:UIControlEventTouchUpInside]; 67 | [_bgview addSubview:backBtn]; 68 | } 69 | 70 | - (void)addImgview { 71 | imageView = [[MCCatchView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 72 | imageView.delegate = self; 73 | [imageView prepareData:nil]; 74 | 75 | [_bgview addSubview:imageView]; 76 | 77 | [imageView startAnimate]; 78 | } 79 | 80 | - (void)initAVCaptureSession { 81 | 82 | self.session = [[AVCaptureSession alloc] init]; 83 | 84 | NSError *error; 85 | 86 | AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 87 | 88 | //更改这个设置的时候必须先锁定设备,修改完后再解锁,否则崩溃 89 | [device lockForConfiguration:nil]; 90 | //设置闪光灯为自动 91 | // [device setFlashMode:AVCaptureFlashModeAuto]; 92 | [device unlockForConfiguration]; 93 | 94 | self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error]; 95 | if (error) { 96 | NSLog(@"%@", error); 97 | } 98 | self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; 99 | //输出设置。AVVideoCodecJPEG 输出jpeg格式图片 100 | NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; 101 | [self.stillImageOutput setOutputSettings:outputSettings]; 102 | 103 | if ([self.session canAddInput:self.videoInput]) { 104 | [self.session addInput:self.videoInput]; 105 | } 106 | if ([self.session canAddOutput:self.stillImageOutput]) { 107 | [self.session addOutput:self.stillImageOutput]; 108 | } 109 | 110 | //初始化预览图层 111 | self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; 112 | [self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect]; 113 | 114 | // NSLog(@"%f",kMainScreenWidth); 115 | self.previewLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 116 | [self.view.layer addSublayer:self.previewLayer]; 117 | // UIView * view =[[UIView alloc]initWithFrame:CGRectMake(-300, 10, 320*3, 20)]; 118 | // view.backgroundColor = [UIColor redColor]; 119 | // [_previewLayer addSubview:view.layer]; 120 | } 121 | 122 | #pragma mark - MCCatchViewDelegate 123 | - (void)catchRedPacket { 124 | [self actionBackBtn]; 125 | } 126 | 127 | - (void)actionBackBtn { 128 | [self.session stopRunning]; 129 | [imageView.timer invalidate]; 130 | imageView.timer = nil; 131 | [imageView stopAnimate]; 132 | [imageView.myImageView removeFromSuperview]; 133 | [self dismissViewControllerAnimated:YES completion:nil]; 134 | } 135 | 136 | - (void)dealloc { 137 | 138 | } 139 | 140 | - (void)didReceiveMemoryWarning { 141 | [super didReceiveMemoryWarning]; 142 | // Dispose of any resources that can be recreated. 143 | } 144 | 145 | /* 146 | #pragma mark - Navigation 147 | 148 | // In a storyboard-based application, you will often want to do a little preparation before navigation 149 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 150 | // Get the new view controller using [segue destinationViewController]. 151 | // Pass the selected object to the new view controller. 152 | } 153 | */ 154 | 155 | @end 156 | -------------------------------------------------------------------------------- /MCCatchRedPacket/YLGIFImage/YLImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // YLImageView.m 3 | // YLGIFImage 4 | // 5 | // Created by Yong Li on 14-3-2. 6 | // Copyright (c) 2014年 Yong Li. All rights reserved. 7 | // 8 | 9 | #import "YLImageView.h" 10 | #import "YLGIFImage.h" 11 | #import 12 | 13 | @interface YLImageView () 14 | 15 | @property (nonatomic, strong) YLGIFImage *animatedImage; 16 | @property (nonatomic, strong) CADisplayLink *displayLink; 17 | @property (nonatomic) NSTimeInterval accumulator; 18 | @property (nonatomic) NSUInteger currentFrameIndex; 19 | @property (nonatomic, strong) UIImage* currentFrame; 20 | @property (nonatomic) NSUInteger loopCountdown; 21 | 22 | @end 23 | 24 | @implementation YLImageView 25 | 26 | const NSTimeInterval kMaxTimeStep = 1; // note: To avoid spiral-o-death 27 | 28 | @synthesize runLoopMode = _runLoopMode; 29 | @synthesize displayLink = _displayLink; 30 | 31 | - (id)init 32 | { 33 | self = [super init]; 34 | if (self) { 35 | self.currentFrameIndex = 0; 36 | } 37 | return self; 38 | } 39 | 40 | - (CADisplayLink *)displayLink 41 | { 42 | if (self.superview) { 43 | if (!_displayLink && self.animatedImage) { 44 | _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(changeKeyframe:)]; 45 | [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.runLoopMode]; 46 | } 47 | } else { 48 | [_displayLink invalidate]; 49 | _displayLink = nil; 50 | } 51 | return _displayLink; 52 | } 53 | 54 | - (NSString *)runLoopMode 55 | { 56 | return _runLoopMode ?: NSRunLoopCommonModes; 57 | } 58 | 59 | - (void)setRunLoopMode:(NSString *)runLoopMode 60 | { 61 | if (runLoopMode != _runLoopMode) { 62 | [self stopAnimating]; 63 | 64 | NSRunLoop *runloop = [NSRunLoop mainRunLoop]; 65 | [self.displayLink removeFromRunLoop:runloop forMode:_runLoopMode]; 66 | [self.displayLink addToRunLoop:runloop forMode:runLoopMode]; 67 | 68 | _runLoopMode = runLoopMode; 69 | 70 | [self startAnimating]; 71 | } 72 | } 73 | 74 | - (void)setImage:(UIImage *)image 75 | { 76 | if (image == self.image) { 77 | return; 78 | } 79 | 80 | [self stopAnimating]; 81 | 82 | self.currentFrameIndex = 0; 83 | self.loopCountdown = 0; 84 | self.accumulator = 0; 85 | 86 | if ([image isKindOfClass:[YLGIFImage class]] && image.images) { 87 | if([image.images[0] isKindOfClass:UIImage.class]) 88 | [super setImage:image.images[0]]; 89 | else 90 | [super setImage:nil]; 91 | self.currentFrame = nil; 92 | self.animatedImage = (YLGIFImage *)image; 93 | self.loopCountdown = self.animatedImage.loopCount ?: NSUIntegerMax; 94 | [self startAnimating]; 95 | } else { 96 | self.animatedImage = nil; 97 | [super setImage:image]; 98 | } 99 | [self.layer setNeedsDisplay]; 100 | } 101 | 102 | - (void)setAnimatedImage:(YLGIFImage *)animatedImage 103 | { 104 | _animatedImage = animatedImage; 105 | if (animatedImage == nil) { 106 | self.layer.contents = nil; 107 | } 108 | } 109 | 110 | - (BOOL)isAnimating 111 | { 112 | return [super isAnimating] || (self.displayLink && !self.displayLink.isPaused); 113 | } 114 | 115 | - (void)stopAnimating 116 | { 117 | if (!self.animatedImage) { 118 | [super stopAnimating]; 119 | return; 120 | } 121 | 122 | self.loopCountdown = 0; 123 | 124 | self.displayLink.paused = YES; 125 | } 126 | 127 | - (void)startAnimating 128 | { 129 | if (!self.animatedImage) { 130 | [super startAnimating]; 131 | return; 132 | } 133 | 134 | if (self.isAnimating) { 135 | return; 136 | } 137 | 138 | self.loopCountdown = self.animatedImage.loopCount ?: NSUIntegerMax; 139 | 140 | self.displayLink.paused = NO; 141 | } 142 | 143 | - (void)changeKeyframe:(CADisplayLink *)displayLink 144 | { 145 | if (self.currentFrameIndex >= [self.animatedImage.images count]) { 146 | return; 147 | } 148 | self.accumulator += fmin(displayLink.duration, kMaxTimeStep); 149 | 150 | while (self.accumulator >= self.animatedImage.frameDurations[self.currentFrameIndex]) { 151 | self.accumulator -= self.animatedImage.frameDurations[self.currentFrameIndex]; 152 | if (++self.currentFrameIndex >= [self.animatedImage.images count]) { 153 | if (--self.loopCountdown == 0) { 154 | [self stopAnimating]; 155 | return; 156 | } 157 | self.currentFrameIndex = 0; 158 | } 159 | self.currentFrameIndex = MIN(self.currentFrameIndex, [self.animatedImage.images count] - 1); 160 | self.currentFrame = [self.animatedImage getFrameWithIndex:self.currentFrameIndex]; 161 | [self.layer setNeedsDisplay]; 162 | } 163 | } 164 | 165 | - (void)displayLayer:(CALayer *)layer 166 | { 167 | if (!self.animatedImage || [self.animatedImage.images count] == 0) { 168 | return; 169 | } 170 | //NSLog(@"display index: %luu", (unsigned long)self.currentFrameIndex); 171 | if(self.currentFrame && ![self.currentFrame isKindOfClass:[NSNull class]]) 172 | layer.contents = (__bridge id)([self.currentFrame CGImage]); 173 | } 174 | 175 | - (void)didMoveToWindow 176 | { 177 | [super didMoveToWindow]; 178 | if (self.window) { 179 | [self startAnimating]; 180 | } else { 181 | dispatch_async(dispatch_get_main_queue(), ^{ 182 | if (!self.window) { 183 | [self stopAnimating]; 184 | } 185 | }); 186 | } 187 | } 188 | 189 | - (void)didMoveToSuperview 190 | { 191 | [super didMoveToSuperview]; 192 | if (self.superview) { 193 | //Has a superview, make sure it has a displayLink 194 | [self displayLink]; 195 | } else { 196 | //Doesn't have superview, let's check later if we need to remove the displayLink 197 | dispatch_async(dispatch_get_main_queue(), ^{ 198 | [self displayLink]; 199 | }); 200 | } 201 | } 202 | 203 | - (void)setHighlighted:(BOOL)highlighted 204 | { 205 | if (!self.animatedImage) { 206 | [super setHighlighted:highlighted]; 207 | } 208 | } 209 | 210 | - (UIImage *)image 211 | { 212 | return self.animatedImage ?: [super image]; 213 | } 214 | 215 | - (CGSize)sizeThatFits:(CGSize)size 216 | { 217 | return self.image.size; 218 | } 219 | 220 | @end 221 | 222 | -------------------------------------------------------------------------------- /MCCatchRedPacket/YLGIFImage/YLGIFImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // YLGIFImage.m 3 | // YLGIFImage 4 | // 5 | // Created by Yong Li on 14-3-2. 6 | // Copyright (c) 2014年 Yong Li. All rights reserved. 7 | // 8 | 9 | #import "YLGIFImage.h" 10 | #import 11 | #import 12 | 13 | 14 | //Define FLT_EPSILON because, reasons. 15 | //Actually, I don't know why but it seems under certain circumstances it is not defined 16 | #ifndef FLT_EPSILON 17 | #define FLT_EPSILON __FLT_EPSILON__ 18 | #endif 19 | 20 | inline static NSTimeInterval CGImageSourceGetGifFrameDelay(CGImageSourceRef imageSource, NSUInteger index) 21 | { 22 | NSTimeInterval frameDuration = 0; 23 | CFDictionaryRef theImageProperties; 24 | if ((theImageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, index, NULL))) { 25 | CFDictionaryRef gifProperties; 26 | if (CFDictionaryGetValueIfPresent(theImageProperties, kCGImagePropertyGIFDictionary, (const void **)&gifProperties)) { 27 | const void *frameDurationValue; 28 | if (CFDictionaryGetValueIfPresent(gifProperties, kCGImagePropertyGIFUnclampedDelayTime, &frameDurationValue)) { 29 | frameDuration = [(__bridge NSNumber *)frameDurationValue doubleValue]; 30 | if (frameDuration <= 0) { 31 | if (CFDictionaryGetValueIfPresent(gifProperties, kCGImagePropertyGIFDelayTime, &frameDurationValue)) { 32 | frameDuration = [(__bridge NSNumber *)frameDurationValue doubleValue]; 33 | } 34 | } 35 | } 36 | } 37 | CFRelease(theImageProperties); 38 | } 39 | 40 | #ifndef OLExactGIFRepresentation 41 | //Implement as Browsers do. 42 | //See: http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-frame-delay-browser-compatibility 43 | //Also: http://blogs.msdn.com/b/ieinternals/archive/2010/06/08/animated-gifs-slow-down-to-under-20-frames-per-second.aspx 44 | 45 | if (frameDuration < 0.02 - FLT_EPSILON) { 46 | frameDuration = 0.1; 47 | } 48 | #endif 49 | return frameDuration; 50 | } 51 | 52 | inline static BOOL CGImageSourceContainsAnimatedGif(CGImageSourceRef imageSource) 53 | { 54 | return imageSource && UTTypeConformsTo(CGImageSourceGetType(imageSource), kUTTypeGIF) && CGImageSourceGetCount(imageSource) > 1; 55 | } 56 | 57 | inline static BOOL isRetinaFilePath(NSString *path) 58 | { 59 | NSRange retinaSuffixRange = [[path lastPathComponent] rangeOfString:@"@2x" options:NSCaseInsensitiveSearch]; 60 | return retinaSuffixRange.length && retinaSuffixRange.location != NSNotFound; 61 | } 62 | 63 | @interface YLGIFImage () 64 | 65 | @property (nonatomic, readwrite) NSMutableArray *images; 66 | @property (nonatomic, readwrite) NSTimeInterval *frameDurations; 67 | @property (nonatomic, readwrite) NSTimeInterval totalDuration; 68 | @property (nonatomic, readwrite) NSUInteger loopCount; 69 | @property (nonatomic, readwrite) CGImageSourceRef incrementalSource; 70 | 71 | @end 72 | 73 | static NSUInteger _prefetchedNum = 10; 74 | 75 | @implementation YLGIFImage 76 | { 77 | dispatch_queue_t readFrameQueue; 78 | CGImageSourceRef _imageSourceRef; 79 | CGFloat _scale; 80 | } 81 | 82 | @synthesize images; 83 | 84 | #pragma mark - Class Methods 85 | 86 | + (id)imageNamed:(NSString *)name 87 | { 88 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 89 | 90 | return ([[NSFileManager defaultManager] fileExistsAtPath:path]) ? [self imageWithContentsOfFile:path] : nil; 91 | } 92 | 93 | + (id)imageWithContentsOfFile:(NSString *)path 94 | { 95 | return [self imageWithData:[NSData dataWithContentsOfFile:path] 96 | scale:isRetinaFilePath(path) ? 2.0f : 1.0f]; 97 | } 98 | 99 | + (id)imageWithData:(NSData *)data 100 | { 101 | return [self imageWithData:data scale:1.0f]; 102 | } 103 | 104 | + (id)imageWithData:(NSData *)data scale:(CGFloat)scale 105 | { 106 | if (!data) { 107 | return nil; 108 | } 109 | 110 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)(data), NULL); 111 | UIImage *image; 112 | 113 | if (CGImageSourceContainsAnimatedGif(imageSource)) { 114 | image = [[self alloc] initWithCGImageSource:imageSource scale:scale]; 115 | } else { 116 | image = [super imageWithData:data scale:scale]; 117 | } 118 | 119 | if (imageSource) { 120 | CFRelease(imageSource); 121 | } 122 | 123 | return image; 124 | } 125 | 126 | #pragma mark - Initialization methods 127 | 128 | - (id)initWithContentsOfFile:(NSString *)path 129 | { 130 | return [self initWithData:[NSData dataWithContentsOfFile:path] 131 | scale:isRetinaFilePath(path) ? 2.0f : 1.0f]; 132 | } 133 | 134 | - (id)initWithData:(NSData *)data 135 | { 136 | return [self initWithData:data scale:1.0f]; 137 | } 138 | 139 | - (id)initWithData:(NSData *)data scale:(CGFloat)scale 140 | { 141 | if (!data) { 142 | return nil; 143 | } 144 | 145 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)(data), NULL); 146 | 147 | if (CGImageSourceContainsAnimatedGif(imageSource)) { 148 | self = [self initWithCGImageSource:imageSource scale:scale]; 149 | } else { 150 | if (scale == 1.0f) { 151 | self = [super initWithData:data]; 152 | } else { 153 | self = [super initWithData:data scale:scale]; 154 | } 155 | } 156 | 157 | if (imageSource) { 158 | CFRelease(imageSource); 159 | } 160 | 161 | return self; 162 | } 163 | 164 | - (id)initWithCGImageSource:(CGImageSourceRef)imageSource scale:(CGFloat)scale 165 | { 166 | self = [super init]; 167 | if (!imageSource || !self) { 168 | return nil; 169 | } 170 | 171 | CFRetain(imageSource); 172 | 173 | NSUInteger numberOfFrames = CGImageSourceGetCount(imageSource); 174 | 175 | NSDictionary *imageProperties = CFBridgingRelease(CGImageSourceCopyProperties(imageSource, NULL)); 176 | NSDictionary *gifProperties = [imageProperties objectForKey:(NSString *)kCGImagePropertyGIFDictionary]; 177 | 178 | self.frameDurations = (NSTimeInterval *)malloc(numberOfFrames * sizeof(NSTimeInterval)); 179 | self.loopCount = [gifProperties[(NSString *)kCGImagePropertyGIFLoopCount] unsignedIntegerValue]; 180 | self.images = [NSMutableArray arrayWithCapacity:numberOfFrames]; 181 | 182 | NSNull *aNull = [NSNull null]; 183 | for (NSUInteger i = 0; i < numberOfFrames; ++i) { 184 | [self.images addObject:aNull]; 185 | NSTimeInterval frameDuration = CGImageSourceGetGifFrameDelay(imageSource, i); 186 | self.frameDurations[i] = frameDuration; 187 | self.totalDuration += frameDuration; 188 | } 189 | //CFTimeInterval start = CFAbsoluteTimeGetCurrent(); 190 | // Load first frame 191 | NSUInteger num = MIN(_prefetchedNum, numberOfFrames); 192 | for (NSUInteger i=0; i _prefetchedNum) { 228 | if(idx != 0) { 229 | [self.images replaceObjectAtIndex:idx withObject:[NSNull null]]; 230 | } 231 | NSUInteger nextReadIdx = (idx + _prefetchedNum); 232 | for(NSUInteger i=idx+1; i<=nextReadIdx; i++) { 233 | NSUInteger _idx = i%self.images.count; 234 | if([self.images[_idx] isKindOfClass:[NSNull class]]) { 235 | dispatch_async(readFrameQueue, ^{ 236 | CGImageRef image = CGImageSourceCreateImageAtIndex(_imageSourceRef, _idx, NULL); 237 | @synchronized(self.images) { 238 | if (image != NULL) { 239 | [self.images replaceObjectAtIndex:_idx withObject:[UIImage imageWithCGImage:image scale:_scale orientation:UIImageOrientationUp]]; 240 | CFRelease(image); 241 | } else { 242 | [self.images replaceObjectAtIndex:_idx withObject:[NSNull null]]; 243 | } 244 | } 245 | }); 246 | } 247 | } 248 | } 249 | return frame; 250 | } 251 | 252 | #pragma mark - Compatibility methods 253 | 254 | - (CGSize)size 255 | { 256 | if (self.images.count) { 257 | return [[self.images objectAtIndex:0] size]; 258 | } 259 | return [super size]; 260 | } 261 | 262 | - (CGImageRef)CGImage 263 | { 264 | if (self.images.count) { 265 | return [[self.images objectAtIndex:0] CGImage]; 266 | } else { 267 | return [super CGImage]; 268 | } 269 | } 270 | 271 | - (UIImageOrientation)imageOrientation 272 | { 273 | if (self.images.count) { 274 | return [[self.images objectAtIndex:0] imageOrientation]; 275 | } else { 276 | return [super imageOrientation]; 277 | } 278 | } 279 | 280 | - (CGFloat)scale 281 | { 282 | if (self.images.count) { 283 | return [(UIImage *)[self.images objectAtIndex:0] scale]; 284 | } else { 285 | return [super scale]; 286 | } 287 | } 288 | 289 | - (NSTimeInterval)duration 290 | { 291 | return self.images ? self.totalDuration : [super duration]; 292 | } 293 | 294 | - (void)dealloc { 295 | if(_imageSourceRef) { 296 | CFRelease(_imageSourceRef); 297 | } 298 | free(_frameDurations); 299 | if (_incrementalSource) { 300 | CFRelease(_incrementalSource); 301 | } 302 | } 303 | 304 | @end 305 | -------------------------------------------------------------------------------- /MCCatchRedPacket/MCcatchView/MCCatchView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MCCatchView.m 3 | // MCCatchRedPacket 4 | // 5 | // Created by MC on 16/10/29. 6 | // Copyright © 2016年 MC. All rights reserved. 7 | // 8 | 9 | #import "MCCatchView.h" 10 | #import "YGGravity.h" 11 | #define KRedPacket_w 90 12 | #define KRedPacket_h ((90 * 515) / 607) 13 | 14 | #define SPEED 50 15 | @interface MCCatchView () { 16 | 17 | NSMutableArray *imgViewArray; 18 | NSInteger index; 19 | 20 | CGRect catchRect; 21 | } 22 | 23 | @end 24 | 25 | @implementation MCCatchView 26 | 27 | - (instancetype)initWithFrame:(CGRect)frame { 28 | self = [super initWithFrame:frame]; 29 | if (self) { 30 | imgViewArray = [NSMutableArray array]; 31 | index = 100; 32 | [self configUI]; 33 | } 34 | return self; 35 | } 36 | 37 | - (void)drawRect2:(CGRect)rect { 38 | //背景 39 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:0]; 40 | CGFloat w = self.frame.size.width - 170; 41 | 42 | //镂空 43 | UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(85, (self.frame.size.height - w) / 2 - 100, w, w)]; 44 | 45 | [path appendPath:circlePath]; 46 | [path setUsesEvenOddFillRule:YES]; 47 | 48 | CAShapeLayer *fillLayer = [CAShapeLayer layer]; 49 | fillLayer.path = path.CGPath; 50 | fillLayer.fillRule = kCAFillRuleEvenOdd; //中间镂空的关键点 填充规则 51 | fillLayer.fillColor = [UIColor blackColor].CGColor; 52 | fillLayer.opacity = 0.5; 53 | [self.layer addSublayer:fillLayer]; 54 | } 55 | 56 | - (void)configUI { 57 | 58 | _myImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width * 3, self.frame.size.height * 2)]; 59 | 60 | _myImageView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2); 61 | [self addSubview:_myImageView]; 62 | 63 | // _myImageView.backgroundColor = [UIColor redColor]; 64 | 65 | _flightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width * 3, self.frame.size.height)]; 66 | _flightView.backgroundColor = [UIColor clearColor]; 67 | [_myImageView addSubview:_flightView]; 68 | 69 | [self drawRect2:self.frame]; 70 | 71 | CGFloat x = 50; 72 | CGFloat w = self.frame.size.width - 100; 73 | CGFloat h = w; 74 | CGFloat y = (self.frame.size.height - h) / 2 - 100; 75 | 76 | _catchView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)]; 77 | _catchView.image = [UIImage imageNamed:@"ic_circle_normal"]; 78 | 79 | // [self addGestureRecognizer:tap]; 80 | _catchView.userInteractionEnabled = YES; 81 | 82 | [self addSubview:_catchView]; 83 | 84 | y += h + 100; 85 | w = 70; 86 | h = 70; 87 | x = (self.frame.size.width - w) / 2; 88 | 89 | _catchBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)]; 90 | [_catchBtn setImage:[UIImage imageNamed:@"btn_catch_normal"] forState:UIControlStateNormal]; 91 | [_catchBtn setImage:[UIImage imageNamed:@"btn_catch"] forState:UIControlStateSelected]; 92 | [_catchBtn addTarget:self action:@selector(actionCatchBtn) forControlEvents:UIControlEventTouchUpInside]; 93 | [self addSubview:_catchBtn]; 94 | 95 | // CGFloat w2 = 320/3-80; 96 | // CGFloat x2 = (self.frame.size.width-w2)/2; 97 | // 98 | // CGFloat h2 = w2; 99 | // CGFloat y2 = (self.frame.size.height - h2)/2-h2-75; 100 | // UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(x2, y2, w2, h2)]; 101 | // view2.backgroundColor = [UIColor redColor]; 102 | // [self addSubview:view2]; 103 | 104 | UIImageView *ic_arrowImgVie = [[UIImageView alloc] initWithFrame:CGRectMake(_catchView.frame.origin.x - 10 / 2, _catchView.frame.origin.y - 10 / 2, _catchView.frame.size.width + 10, _catchView.frame.size.height + 10)]; 105 | 106 | ic_arrowImgVie.image = [UIImage imageNamed:@"ic_arrow"]; 107 | ic_arrowImgVie.userInteractionEnabled = YES; 108 | [self addSubview:ic_arrowImgVie]; 109 | 110 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionRedPacket_catchViewTap:)]; 111 | 112 | [ic_arrowImgVie addGestureRecognizer:tap]; 113 | } 114 | 115 | - (void)actionCatchBtn { 116 | if (_catchBtn.selected) { 117 | if (_delegate) { 118 | [_delegate catchRedPacket]; 119 | } 120 | } 121 | } 122 | 123 | - (void)prepareData:(NSArray *)array { 124 | //607*515 125 | CGFloat RedPacket_w = 100; 126 | CGFloat RedPacket_h = 100; 127 | RedPacket_w = 90 * 515 / 607; 128 | RedPacket_h = 90 * 515 / 607; 129 | 130 | CGFloat maxx = self.frame.size.width * 3 - RedPacket_w; 131 | 132 | CGFloat maxy = self.frame.size.height - RedPacket_h; 133 | 134 | for (NSInteger i = 0; i < 4; i++) { 135 | CGFloat randomx = arc4random() % ((NSInteger) maxx); 136 | 137 | CGFloat randomy = arc4random() % ((NSInteger) maxy); 138 | 139 | RedPacketView *RedPacket = [[RedPacketView alloc] initWithFrame:CGRectMake(randomx, randomy, KRedPacket_w, KRedPacket_h)]; 140 | 141 | RedPacket.image = [YLGIFImage imageNamed:@"bird.gif"]; 142 | // RedPacket.backgroundColor = [UIColor blueColor]; 143 | RedPacket.tag = 900 + i; 144 | 145 | // UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(actionRedPacketTap:)]; 146 | // [RedPacket addGestureRecognizer:tap]; 147 | RedPacket.userInteractionEnabled = YES; 148 | 149 | [_flightView addSubview:RedPacket]; 150 | 151 | [imgViewArray addObject:RedPacket]; 152 | 153 | [self RedPacketFiy2:RedPacket]; 154 | } 155 | _timer = [NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(jianCe) userInfo:nil repeats:YES]; 156 | } 157 | 158 | - (void)jianCe { 159 | for (NSInteger i = 0; i < 4; i++) { 160 | RedPacketView *view1 = [self viewWithTag:900 + i]; 161 | CGRect rect = [[view1.layer presentationLayer] frame]; // view指你的动画中移动的view 162 | 163 | if (CGRectIntersectsRect(rect, catchRect)) { 164 | _catchBtn.selected = YES; 165 | _catchView.image = [UIImage imageNamed:@"ic_circle"]; 166 | 167 | // NSLog(@"进来了"); 168 | [UIView animateWithDuration:.1 animations:^{ 169 | 170 | _catchView.transform = CGAffineTransformScale(_catchView.transform, .98, .98); 171 | 172 | } 173 | completion:^(BOOL finished) { 174 | 175 | _catchView.transform = CGAffineTransformIdentity; 176 | 177 | }]; 178 | 179 | break; 180 | 181 | } else { 182 | // NSLog(@"出去了"); 183 | _catchView.image = [UIImage imageNamed:@"ic_circle_normal"]; 184 | _catchView.transform = CGAffineTransformIdentity; 185 | 186 | _catchBtn.selected = NO; 187 | } 188 | } 189 | } 190 | 191 | - (void)RedPacketFiy2:(RedPacketView *)RedPacket { 192 | CGFloat RedPacket_w = KRedPacket_w; 193 | CGFloat RedPacket_h = KRedPacket_h; 194 | 195 | CGFloat maxx = self.frame.size.width * 3 - RedPacket_w; 196 | 197 | CGFloat maxy = self.frame.size.height - RedPacket_h; 198 | 199 | CGFloat random_x = arc4random() % ((NSInteger) maxx); 200 | 201 | CGFloat random_y = arc4random() % ((NSInteger) maxy); 202 | 203 | // CGFloat random_y = arc4random() % ((NSInteger)maxy); 204 | 205 | CGFloat Scalenum = [self randomBetween:0.5 And:3]; 206 | 207 | if (RedPacket.state_size == 1 || RedPacket.state_size == 2) { 208 | 209 | //需要还原 210 | [UIView animateWithDuration:3 animations:^{ 211 | 212 | RedPacket.frame = CGRectMake(random_x, random_y, RedPacket.frame.size.width, RedPacket.frame.size.height); 213 | RedPacket.transform = CGAffineTransformIdentity; 214 | RedPacket.state_size = 0; 215 | 216 | } 217 | completion:^(BOOL finished) { 218 | if (_timer) { 219 | [self RedPacketFiy2:RedPacket]; 220 | } 221 | }]; 222 | 223 | } 224 | 225 | else { 226 | [UIView animateWithDuration:3 animations:^{ 227 | 228 | RedPacket.frame = CGRectMake(random_x, random_y, RedPacket.frame.size.width, RedPacket.frame.size.height); 229 | RedPacket.transform = CGAffineTransformScale(RedPacket.transform, Scalenum, Scalenum); 230 | 231 | if (Scalenum > 1) { 232 | RedPacket.state_size = 2; 233 | 234 | } else if (Scalenum < 1) { 235 | 236 | RedPacket.state_size = 1; 237 | 238 | } else { 239 | RedPacket.state_size = 0; 240 | } 241 | 242 | } 243 | completion:^(BOOL finished) { 244 | 245 | if (_timer) { 246 | [self RedPacketFiy2:RedPacket]; 247 | } 248 | 249 | }]; 250 | } 251 | } 252 | 253 | - (void)actionRedPacket_catchViewTap:(UITapGestureRecognizer *)tap { 254 | // RedPacketView * RedPacket = [self viewWithTag:tap.view.tag]; 255 | // NSLog(@"RedPacket.tag ==%ld",RedPacket.tag); 256 | 257 | // UITouch *touch = [touches anyObject]; 258 | // 259 | // CGPoint touchPoint = [touch locationInView:self]; 260 | CGPoint point = [tap locationInView:self]; 261 | NSLog(@"handleSingleTap!pointx:%f,y:%f", point.x, point.y); 262 | 263 | for (NSInteger i = 0; i < 4; i++) { 264 | RedPacketView *view1 = [self viewWithTag:900 + i]; 265 | CGRect rect = [[view1.layer presentationLayer] frame]; // view指你的动画中移动的view 266 | 267 | if (CGRectIntersectsRect(rect, catchRect)) { 268 | NSLog(@"进来了"); 269 | [self actionCatchBtn]; 270 | 271 | // if( CGRectIntersectsRect(rect, CGRectMake(point.x+self.frame.size.width, point.y, 30, 30))) 272 | // { 273 | // NSLog(@"捉到了"); 274 | // 275 | // } 276 | break; 277 | 278 | } else { 279 | } 280 | } 281 | } 282 | 283 | //-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event 284 | //{ 285 | // NSArray *subViews = self.subviews; 286 | // 287 | // for(UIView *subView in subViews){ 288 | // 289 | // if([subView isKindOfClass:[RedPacketView class]]){ //是要找的图片 290 | // CALayer *layer = subView.layer.presentationLayer; //图片的显示层 291 | // if(CGRectContainsPoint(layer.frame, point)){ //触摸点在显示层中,返回当前图片 292 | // return subView; 293 | // } 294 | // } 295 | // if([subView isKindOfClass:[UIImageView class]]){ //是要找的图片 296 | // CALayer *layer = subView.layer.presentationLayer; //图片的显示层 297 | // if(CGRectContainsPoint(layer.frame, point)){ //触摸点在显示层中,返回当前图片 298 | // return subView; 299 | // } 300 | // } 301 | // 302 | // } 303 | // return [super hitTest:point withEvent:event]; 304 | //} 305 | 306 | - (void)startAnimate { 307 | float scrollSpeed = (_myImageView.frame.size.width - self.frame.size.width) / 2 / SPEED; 308 | float scrollSpeedH = (_myImageView.frame.size.height - self.frame.size.height) / 2 / SPEED; 309 | 310 | [YGGravity sharedGravity].timeInterval = 0.03; 311 | 312 | __weak typeof(&*self) weakSelf = self; 313 | [[YGGravity sharedGravity] startDeviceMotionUpdatesBlock:^(float x, float y, float z) { 314 | 315 | [UIView animateKeyframesWithDuration:1 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeDiscrete | UIViewAnimationOptionAllowUserInteraction animations:^{ 316 | 317 | if ((weakSelf.myImageView.frame.origin.x <= 0 && weakSelf.myImageView.frame.origin.x >= weakSelf.frame.size.width - weakSelf.myImageView.frame.size.width) || (weakSelf.myImageView.frame.origin.y >= 0 && weakSelf.myImageView.frame.origin.y >= weakSelf.frame.size.height - weakSelf.myImageView.frame.size.height)) { 318 | float invertedYRotationRate = y * 1.0; 319 | 320 | float interpretedXOffset = weakSelf.myImageView.frame.origin.x + invertedYRotationRate * (weakSelf.myImageView.frame.size.width / [UIScreen mainScreen].bounds.size.width) * scrollSpeed + weakSelf.myImageView.frame.size.width / 2; 321 | 322 | float invertedYRotationRatey = x * 1.0; 323 | 324 | float interpretedXOffsety = weakSelf.myImageView.frame.origin.y + invertedYRotationRatey * (weakSelf.myImageView.frame.size.height / [UIScreen mainScreen].bounds.size.height) * scrollSpeedH + weakSelf.myImageView.frame.size.height / 2; 325 | 326 | weakSelf.myImageView.center = CGPointMake(interpretedXOffset, interpretedXOffsety); 327 | } 328 | 329 | if (weakSelf.myImageView.frame.origin.x > 0) { 330 | weakSelf.myImageView.frame = CGRectMake(0, weakSelf.myImageView.frame.origin.y, weakSelf.myImageView.frame.size.width, weakSelf.myImageView.frame.size.height); 331 | } 332 | if (weakSelf.myImageView.frame.origin.y > 0) { 333 | weakSelf.myImageView.frame = CGRectMake(weakSelf.myImageView.frame.origin.x, 0, weakSelf.myImageView.frame.size.width, weakSelf.myImageView.frame.size.height); 334 | } 335 | 336 | if (weakSelf.myImageView.frame.origin.x < weakSelf.frame.size.width - weakSelf.myImageView.frame.size.width) { 337 | weakSelf.myImageView.frame = CGRectMake(weakSelf.frame.size.width - weakSelf.myImageView.frame.size.width, weakSelf.myImageView.frame.origin.y, weakSelf.myImageView.frame.size.width, weakSelf.myImageView.frame.size.height); 338 | } 339 | if (weakSelf.myImageView.frame.origin.y < weakSelf.frame.size.height - weakSelf.myImageView.frame.size.height) { 340 | weakSelf.myImageView.frame = CGRectMake(weakSelf.myImageView.frame.origin.x, weakSelf.frame.size.height - weakSelf.myImageView.frame.size.height, weakSelf.myImageView.frame.size.width, weakSelf.myImageView.frame.size.height); 341 | } 342 | // NSLog(@"y ======%f",_myImageView.frame.origin.y); 343 | if (weakSelf.myImageView.frame.origin.y < -weakSelf.frame.size.height - weakSelf.myImageView.frame.origin.y - 100) { 344 | 345 | weakSelf.myImageView.center = CGPointMake(weakSelf.frame.size.width / 2, weakSelf.frame.size.height / 2); 346 | } 347 | 348 | // NSLog(@"x=======%.2f",_myImageView.frame.origin.x); 349 | // NSLog(@"y=======%.2f",_myImageView.frame.origin.y); 350 | 351 | } 352 | completion:nil]; 353 | CGFloat w2 = 320 / 3 - 80; 354 | CGFloat x2 = (weakSelf.frame.size.width - w2) / 2; 355 | //self.frame.size.width - 100-100; 356 | CGFloat h2 = w2; 357 | CGFloat y2 = (weakSelf.frame.size.height - h2) / 2 - h2 - 75; 358 | 359 | // NSLog(@"x=======%.2f",_myImageView.frame.origin.x); 360 | 361 | CGFloat x3 = 0 - weakSelf.myImageView.frame.origin.x + x2; 362 | CGFloat y3 = 0 - weakSelf.myImageView.frame.origin.y + y2; 363 | CGFloat w3 = w2; 364 | CGFloat h3 = y2; 365 | catchRect = CGRectMake(x3, y3, w3, h3); 366 | 367 | }]; 368 | } 369 | 370 | - (void)stopAnimate { 371 | [[YGGravity sharedGravity] stop]; 372 | } 373 | 374 | //随机返回某个区间范围内的值 375 | - (CGFloat)randomBetween:(CGFloat)smallerNumber And:(CGFloat)largerNumber { 376 | //设置精确的位数 377 | int precision = 100; 378 | //先取得他们之间的差值 379 | float subtraction = largerNumber - smallerNumber; 380 | //取绝对值 381 | subtraction = ABS(subtraction); 382 | //乘以精度的位数 383 | subtraction *= precision; 384 | //在差值间随机 385 | float randomNumber = arc4random() % ((int) subtraction + 1); 386 | //随机的结果除以精度的位数 387 | randomNumber /= precision; 388 | //将随机的值加到较小的值上 389 | float result = MIN(smallerNumber, largerNumber) + randomNumber; 390 | //返回结果 391 | return result; 392 | } 393 | 394 | /* 395 | // Only override drawRect: if you perform custom drawing. 396 | // An empty implementation adversely affects performance during animation. 397 | - (void)drawRect:(CGRect)rect { 398 | // Drawing code 399 | } 400 | */ 401 | 402 | @end 403 | -------------------------------------------------------------------------------- /MCCatchRedPacket.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4C7AF80D1DC4898300AFA261 /* btn_close_normal@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C7AF80C1DC4898300AFA261 /* btn_close_normal@2x.png */; }; 11 | 4CAC59391DC47AA800CAA825 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC59381DC47AA800CAA825 /* main.m */; }; 12 | 4CAC593C1DC47AA800CAA825 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC593B1DC47AA800CAA825 /* AppDelegate.m */; }; 13 | 4CAC593F1DC47AA800CAA825 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC593E1DC47AA800CAA825 /* ViewController.m */; }; 14 | 4CAC59441DC47AA800CAA825 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59431DC47AA800CAA825 /* Assets.xcassets */; }; 15 | 4CAC59521DC47AA800CAA825 /* MCCatchRedPacketTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC59511DC47AA800CAA825 /* MCCatchRedPacketTests.m */; }; 16 | 4CAC595D1DC47AA800CAA825 /* MCCatchRedPacketUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC595C1DC47AA800CAA825 /* MCCatchRedPacketUITests.m */; }; 17 | 4CAC596F1DC47B9D00CAA825 /* YLGIFImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC596C1DC47B9D00CAA825 /* YLGIFImage.m */; }; 18 | 4CAC59701DC47B9D00CAA825 /* YLImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC596E1DC47B9D00CAA825 /* YLImageView.m */; }; 19 | 4CAC59731DC47BD400CAA825 /* MCCatchRedPacketController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC59721DC47BD400CAA825 /* MCCatchRedPacketController.m */; }; 20 | 4CAC59771DC47CE100CAA825 /* YGGravity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC59761DC47CE100CAA825 /* YGGravity.m */; }; 21 | 4CAC597A1DC47CFD00CAA825 /* MCCatchView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC59791DC47CFD00CAA825 /* MCCatchView.m */; }; 22 | 4CAC597D1DC47D4700CAA825 /* RedPacketView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAC597C1DC47D4700CAA825 /* RedPacketView.m */; }; 23 | 4CAC59841DC47F9B00CAA825 /* btn_catch.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC597F1DC47F9B00CAA825 /* btn_catch.png */; }; 24 | 4CAC59851DC47F9B00CAA825 /* btn_catch_normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59801DC47F9B00CAA825 /* btn_catch_normal.png */; }; 25 | 4CAC59861DC47F9B00CAA825 /* ic_arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59811DC47F9B00CAA825 /* ic_arrow.png */; }; 26 | 4CAC59871DC47F9B00CAA825 /* ic_circle.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59821DC47F9B00CAA825 /* ic_circle.png */; }; 27 | 4CAC59881DC47F9B00CAA825 /* ic_circle_normal.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59831DC47F9B00CAA825 /* ic_circle_normal.png */; }; 28 | 4CAC598A1DC47FB200CAA825 /* bird.gif in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC59891DC47FB200CAA825 /* bird.gif */; }; 29 | 4CAC598D1DC4823C00CAA825 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC598C1DC4823C00CAA825 /* QuartzCore.framework */; }; 30 | 4CAC598F1DC4824200CAA825 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC598E1DC4824200CAA825 /* AVFoundation.framework */; }; 31 | 4CAC59911DC4824800CAA825 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC59901DC4824800CAA825 /* MobileCoreServices.framework */; }; 32 | 4CAC59931DC4825400CAA825 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC59921DC4825400CAA825 /* MediaPlayer.framework */; }; 33 | 4CAC59951DC4825A00CAA825 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC59941DC4825A00CAA825 /* AssetsLibrary.framework */; }; 34 | 4CAC59971DC4826700CAA825 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC59961DC4826700CAA825 /* CoreMedia.framework */; }; 35 | 4CAC59991DC4826F00CAA825 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CAC59981DC4826F00CAA825 /* CoreMotion.framework */; }; 36 | 4CAC599B1DC4834200CAA825 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4CAC599A1DC4834200CAA825 /* Default-568h@2x.png */; }; 37 | /* End PBXBuildFile section */ 38 | 39 | /* Begin PBXContainerItemProxy section */ 40 | 4CAC594E1DC47AA800CAA825 /* PBXContainerItemProxy */ = { 41 | isa = PBXContainerItemProxy; 42 | containerPortal = 4CAC592C1DC47AA800CAA825 /* Project object */; 43 | proxyType = 1; 44 | remoteGlobalIDString = 4CAC59331DC47AA800CAA825; 45 | remoteInfo = MCCatchRedPacket; 46 | }; 47 | 4CAC59591DC47AA800CAA825 /* PBXContainerItemProxy */ = { 48 | isa = PBXContainerItemProxy; 49 | containerPortal = 4CAC592C1DC47AA800CAA825 /* Project object */; 50 | proxyType = 1; 51 | remoteGlobalIDString = 4CAC59331DC47AA800CAA825; 52 | remoteInfo = MCCatchRedPacket; 53 | }; 54 | /* End PBXContainerItemProxy section */ 55 | 56 | /* Begin PBXFileReference section */ 57 | 4C7AF80C1DC4898300AFA261 /* btn_close_normal@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "btn_close_normal@2x.png"; sourceTree = ""; }; 58 | 4CAC59341DC47AA800CAA825 /* MCCatchRedPacket.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MCCatchRedPacket.app; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | 4CAC59381DC47AA800CAA825 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 60 | 4CAC593A1DC47AA800CAA825 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 61 | 4CAC593B1DC47AA800CAA825 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 62 | 4CAC593D1DC47AA800CAA825 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 63 | 4CAC593E1DC47AA800CAA825 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 64 | 4CAC59431DC47AA800CAA825 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 65 | 4CAC59481DC47AA800CAA825 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 66 | 4CAC594D1DC47AA800CAA825 /* MCCatchRedPacketTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCCatchRedPacketTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 67 | 4CAC59511DC47AA800CAA825 /* MCCatchRedPacketTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCCatchRedPacketTests.m; sourceTree = ""; }; 68 | 4CAC59531DC47AA800CAA825 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 69 | 4CAC59581DC47AA800CAA825 /* MCCatchRedPacketUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCCatchRedPacketUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 70 | 4CAC595C1DC47AA800CAA825 /* MCCatchRedPacketUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCCatchRedPacketUITests.m; sourceTree = ""; }; 71 | 4CAC595E1DC47AA800CAA825 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 72 | 4CAC596B1DC47B9D00CAA825 /* YLGIFImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLGIFImage.h; sourceTree = ""; }; 73 | 4CAC596C1DC47B9D00CAA825 /* YLGIFImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLGIFImage.m; sourceTree = ""; }; 74 | 4CAC596D1DC47B9D00CAA825 /* YLImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YLImageView.h; sourceTree = ""; }; 75 | 4CAC596E1DC47B9D00CAA825 /* YLImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YLImageView.m; sourceTree = ""; }; 76 | 4CAC59711DC47BD400CAA825 /* MCCatchRedPacketController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCCatchRedPacketController.h; sourceTree = ""; }; 77 | 4CAC59721DC47BD400CAA825 /* MCCatchRedPacketController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MCCatchRedPacketController.m; sourceTree = ""; }; 78 | 4CAC59751DC47CE100CAA825 /* YGGravity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGGravity.h; sourceTree = ""; }; 79 | 4CAC59761DC47CE100CAA825 /* YGGravity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YGGravity.m; sourceTree = ""; }; 80 | 4CAC59781DC47CFD00CAA825 /* MCCatchView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCCatchView.h; sourceTree = ""; }; 81 | 4CAC59791DC47CFD00CAA825 /* MCCatchView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MCCatchView.m; sourceTree = ""; }; 82 | 4CAC597B1DC47D4700CAA825 /* RedPacketView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RedPacketView.h; sourceTree = ""; }; 83 | 4CAC597C1DC47D4700CAA825 /* RedPacketView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RedPacketView.m; sourceTree = ""; }; 84 | 4CAC597F1DC47F9B00CAA825 /* btn_catch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = btn_catch.png; sourceTree = ""; }; 85 | 4CAC59801DC47F9B00CAA825 /* btn_catch_normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = btn_catch_normal.png; sourceTree = ""; }; 86 | 4CAC59811DC47F9B00CAA825 /* ic_arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_arrow.png; sourceTree = ""; }; 87 | 4CAC59821DC47F9B00CAA825 /* ic_circle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_circle.png; sourceTree = ""; }; 88 | 4CAC59831DC47F9B00CAA825 /* ic_circle_normal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_circle_normal.png; sourceTree = ""; }; 89 | 4CAC59891DC47FB200CAA825 /* bird.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = bird.gif; sourceTree = ""; }; 90 | 4CAC598C1DC4823C00CAA825 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 91 | 4CAC598E1DC4824200CAA825 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 92 | 4CAC59901DC4824800CAA825 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; 93 | 4CAC59921DC4825400CAA825 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 94 | 4CAC59941DC4825A00CAA825 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 95 | 4CAC59961DC4826700CAA825 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 96 | 4CAC59981DC4826F00CAA825 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; }; 97 | 4CAC599A1DC4834200CAA825 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 98 | /* End PBXFileReference section */ 99 | 100 | /* Begin PBXFrameworksBuildPhase section */ 101 | 4CAC59311DC47AA800CAA825 /* Frameworks */ = { 102 | isa = PBXFrameworksBuildPhase; 103 | buildActionMask = 2147483647; 104 | files = ( 105 | 4CAC59991DC4826F00CAA825 /* CoreMotion.framework in Frameworks */, 106 | 4CAC59971DC4826700CAA825 /* CoreMedia.framework in Frameworks */, 107 | 4CAC59951DC4825A00CAA825 /* AssetsLibrary.framework in Frameworks */, 108 | 4CAC59931DC4825400CAA825 /* MediaPlayer.framework in Frameworks */, 109 | 4CAC59911DC4824800CAA825 /* MobileCoreServices.framework in Frameworks */, 110 | 4CAC598F1DC4824200CAA825 /* AVFoundation.framework in Frameworks */, 111 | 4CAC598D1DC4823C00CAA825 /* QuartzCore.framework in Frameworks */, 112 | ); 113 | runOnlyForDeploymentPostprocessing = 0; 114 | }; 115 | 4CAC594A1DC47AA800CAA825 /* Frameworks */ = { 116 | isa = PBXFrameworksBuildPhase; 117 | buildActionMask = 2147483647; 118 | files = ( 119 | ); 120 | runOnlyForDeploymentPostprocessing = 0; 121 | }; 122 | 4CAC59551DC47AA800CAA825 /* Frameworks */ = { 123 | isa = PBXFrameworksBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | ); 127 | runOnlyForDeploymentPostprocessing = 0; 128 | }; 129 | /* End PBXFrameworksBuildPhase section */ 130 | 131 | /* Begin PBXGroup section */ 132 | 4CAC592B1DC47AA800CAA825 = { 133 | isa = PBXGroup; 134 | children = ( 135 | 4CAC599A1DC4834200CAA825 /* Default-568h@2x.png */, 136 | 4CAC59361DC47AA800CAA825 /* MCCatchRedPacket */, 137 | 4CAC59501DC47AA800CAA825 /* MCCatchRedPacketTests */, 138 | 4CAC595B1DC47AA800CAA825 /* MCCatchRedPacketUITests */, 139 | 4CAC59351DC47AA800CAA825 /* Products */, 140 | 4CAC598B1DC4823C00CAA825 /* Frameworks */, 141 | ); 142 | sourceTree = ""; 143 | }; 144 | 4CAC59351DC47AA800CAA825 /* Products */ = { 145 | isa = PBXGroup; 146 | children = ( 147 | 4CAC59341DC47AA800CAA825 /* MCCatchRedPacket.app */, 148 | 4CAC594D1DC47AA800CAA825 /* MCCatchRedPacketTests.xctest */, 149 | 4CAC59581DC47AA800CAA825 /* MCCatchRedPacketUITests.xctest */, 150 | ); 151 | name = Products; 152 | sourceTree = ""; 153 | }; 154 | 4CAC59361DC47AA800CAA825 /* MCCatchRedPacket */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 4CAC597E1DC47F9B00CAA825 /* img */, 158 | 4CAC59741DC47CBD00CAA825 /* MCcatchView */, 159 | 4CAC596A1DC47B9D00CAA825 /* YLGIFImage */, 160 | 4CAC593A1DC47AA800CAA825 /* AppDelegate.h */, 161 | 4CAC593B1DC47AA800CAA825 /* AppDelegate.m */, 162 | 4CAC593D1DC47AA800CAA825 /* ViewController.h */, 163 | 4CAC593E1DC47AA800CAA825 /* ViewController.m */, 164 | 4CAC59711DC47BD400CAA825 /* MCCatchRedPacketController.h */, 165 | 4CAC59721DC47BD400CAA825 /* MCCatchRedPacketController.m */, 166 | 4CAC59431DC47AA800CAA825 /* Assets.xcassets */, 167 | 4CAC59481DC47AA800CAA825 /* Info.plist */, 168 | 4CAC59371DC47AA800CAA825 /* Supporting Files */, 169 | ); 170 | path = MCCatchRedPacket; 171 | sourceTree = ""; 172 | }; 173 | 4CAC59371DC47AA800CAA825 /* Supporting Files */ = { 174 | isa = PBXGroup; 175 | children = ( 176 | 4CAC59381DC47AA800CAA825 /* main.m */, 177 | ); 178 | name = "Supporting Files"; 179 | sourceTree = ""; 180 | }; 181 | 4CAC59501DC47AA800CAA825 /* MCCatchRedPacketTests */ = { 182 | isa = PBXGroup; 183 | children = ( 184 | 4CAC59511DC47AA800CAA825 /* MCCatchRedPacketTests.m */, 185 | 4CAC59531DC47AA800CAA825 /* Info.plist */, 186 | ); 187 | path = MCCatchRedPacketTests; 188 | sourceTree = ""; 189 | }; 190 | 4CAC595B1DC47AA800CAA825 /* MCCatchRedPacketUITests */ = { 191 | isa = PBXGroup; 192 | children = ( 193 | 4CAC595C1DC47AA800CAA825 /* MCCatchRedPacketUITests.m */, 194 | 4CAC595E1DC47AA800CAA825 /* Info.plist */, 195 | ); 196 | path = MCCatchRedPacketUITests; 197 | sourceTree = ""; 198 | }; 199 | 4CAC596A1DC47B9D00CAA825 /* YLGIFImage */ = { 200 | isa = PBXGroup; 201 | children = ( 202 | 4CAC596B1DC47B9D00CAA825 /* YLGIFImage.h */, 203 | 4CAC596C1DC47B9D00CAA825 /* YLGIFImage.m */, 204 | 4CAC596D1DC47B9D00CAA825 /* YLImageView.h */, 205 | 4CAC596E1DC47B9D00CAA825 /* YLImageView.m */, 206 | ); 207 | path = YLGIFImage; 208 | sourceTree = ""; 209 | }; 210 | 4CAC59741DC47CBD00CAA825 /* MCcatchView */ = { 211 | isa = PBXGroup; 212 | children = ( 213 | 4CAC597B1DC47D4700CAA825 /* RedPacketView.h */, 214 | 4CAC597C1DC47D4700CAA825 /* RedPacketView.m */, 215 | 4CAC59751DC47CE100CAA825 /* YGGravity.h */, 216 | 4CAC59761DC47CE100CAA825 /* YGGravity.m */, 217 | 4CAC59781DC47CFD00CAA825 /* MCCatchView.h */, 218 | 4CAC59791DC47CFD00CAA825 /* MCCatchView.m */, 219 | ); 220 | path = MCcatchView; 221 | sourceTree = ""; 222 | }; 223 | 4CAC597E1DC47F9B00CAA825 /* img */ = { 224 | isa = PBXGroup; 225 | children = ( 226 | 4C7AF80C1DC4898300AFA261 /* btn_close_normal@2x.png */, 227 | 4CAC59891DC47FB200CAA825 /* bird.gif */, 228 | 4CAC597F1DC47F9B00CAA825 /* btn_catch.png */, 229 | 4CAC59801DC47F9B00CAA825 /* btn_catch_normal.png */, 230 | 4CAC59811DC47F9B00CAA825 /* ic_arrow.png */, 231 | 4CAC59821DC47F9B00CAA825 /* ic_circle.png */, 232 | 4CAC59831DC47F9B00CAA825 /* ic_circle_normal.png */, 233 | ); 234 | path = img; 235 | sourceTree = ""; 236 | }; 237 | 4CAC598B1DC4823C00CAA825 /* Frameworks */ = { 238 | isa = PBXGroup; 239 | children = ( 240 | 4CAC59981DC4826F00CAA825 /* CoreMotion.framework */, 241 | 4CAC59961DC4826700CAA825 /* CoreMedia.framework */, 242 | 4CAC59941DC4825A00CAA825 /* AssetsLibrary.framework */, 243 | 4CAC59921DC4825400CAA825 /* MediaPlayer.framework */, 244 | 4CAC59901DC4824800CAA825 /* MobileCoreServices.framework */, 245 | 4CAC598E1DC4824200CAA825 /* AVFoundation.framework */, 246 | 4CAC598C1DC4823C00CAA825 /* QuartzCore.framework */, 247 | ); 248 | name = Frameworks; 249 | sourceTree = ""; 250 | }; 251 | /* End PBXGroup section */ 252 | 253 | /* Begin PBXNativeTarget section */ 254 | 4CAC59331DC47AA800CAA825 /* MCCatchRedPacket */ = { 255 | isa = PBXNativeTarget; 256 | buildConfigurationList = 4CAC59611DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacket" */; 257 | buildPhases = ( 258 | 4CAC59301DC47AA800CAA825 /* Sources */, 259 | 4CAC59311DC47AA800CAA825 /* Frameworks */, 260 | 4CAC59321DC47AA800CAA825 /* Resources */, 261 | ); 262 | buildRules = ( 263 | ); 264 | dependencies = ( 265 | ); 266 | name = MCCatchRedPacket; 267 | productName = MCCatchRedPacket; 268 | productReference = 4CAC59341DC47AA800CAA825 /* MCCatchRedPacket.app */; 269 | productType = "com.apple.product-type.application"; 270 | }; 271 | 4CAC594C1DC47AA800CAA825 /* MCCatchRedPacketTests */ = { 272 | isa = PBXNativeTarget; 273 | buildConfigurationList = 4CAC59641DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacketTests" */; 274 | buildPhases = ( 275 | 4CAC59491DC47AA800CAA825 /* Sources */, 276 | 4CAC594A1DC47AA800CAA825 /* Frameworks */, 277 | 4CAC594B1DC47AA800CAA825 /* Resources */, 278 | ); 279 | buildRules = ( 280 | ); 281 | dependencies = ( 282 | 4CAC594F1DC47AA800CAA825 /* PBXTargetDependency */, 283 | ); 284 | name = MCCatchRedPacketTests; 285 | productName = MCCatchRedPacketTests; 286 | productReference = 4CAC594D1DC47AA800CAA825 /* MCCatchRedPacketTests.xctest */; 287 | productType = "com.apple.product-type.bundle.unit-test"; 288 | }; 289 | 4CAC59571DC47AA800CAA825 /* MCCatchRedPacketUITests */ = { 290 | isa = PBXNativeTarget; 291 | buildConfigurationList = 4CAC59671DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacketUITests" */; 292 | buildPhases = ( 293 | 4CAC59541DC47AA800CAA825 /* Sources */, 294 | 4CAC59551DC47AA800CAA825 /* Frameworks */, 295 | 4CAC59561DC47AA800CAA825 /* Resources */, 296 | ); 297 | buildRules = ( 298 | ); 299 | dependencies = ( 300 | 4CAC595A1DC47AA800CAA825 /* PBXTargetDependency */, 301 | ); 302 | name = MCCatchRedPacketUITests; 303 | productName = MCCatchRedPacketUITests; 304 | productReference = 4CAC59581DC47AA800CAA825 /* MCCatchRedPacketUITests.xctest */; 305 | productType = "com.apple.product-type.bundle.ui-testing"; 306 | }; 307 | /* End PBXNativeTarget section */ 308 | 309 | /* Begin PBXProject section */ 310 | 4CAC592C1DC47AA800CAA825 /* Project object */ = { 311 | isa = PBXProject; 312 | attributes = { 313 | LastUpgradeCheck = 0800; 314 | ORGANIZATIONNAME = MC; 315 | TargetAttributes = { 316 | 4CAC59331DC47AA800CAA825 = { 317 | CreatedOnToolsVersion = 8.0; 318 | DevelopmentTeam = 9D44C6L83U; 319 | ProvisioningStyle = Automatic; 320 | }; 321 | 4CAC594C1DC47AA800CAA825 = { 322 | CreatedOnToolsVersion = 8.0; 323 | ProvisioningStyle = Automatic; 324 | TestTargetID = 4CAC59331DC47AA800CAA825; 325 | }; 326 | 4CAC59571DC47AA800CAA825 = { 327 | CreatedOnToolsVersion = 8.0; 328 | ProvisioningStyle = Automatic; 329 | TestTargetID = 4CAC59331DC47AA800CAA825; 330 | }; 331 | }; 332 | }; 333 | buildConfigurationList = 4CAC592F1DC47AA800CAA825 /* Build configuration list for PBXProject "MCCatchRedPacket" */; 334 | compatibilityVersion = "Xcode 3.2"; 335 | developmentRegion = English; 336 | hasScannedForEncodings = 0; 337 | knownRegions = ( 338 | en, 339 | Base, 340 | ); 341 | mainGroup = 4CAC592B1DC47AA800CAA825; 342 | productRefGroup = 4CAC59351DC47AA800CAA825 /* Products */; 343 | projectDirPath = ""; 344 | projectRoot = ""; 345 | targets = ( 346 | 4CAC59331DC47AA800CAA825 /* MCCatchRedPacket */, 347 | 4CAC594C1DC47AA800CAA825 /* MCCatchRedPacketTests */, 348 | 4CAC59571DC47AA800CAA825 /* MCCatchRedPacketUITests */, 349 | ); 350 | }; 351 | /* End PBXProject section */ 352 | 353 | /* Begin PBXResourcesBuildPhase section */ 354 | 4CAC59321DC47AA800CAA825 /* Resources */ = { 355 | isa = PBXResourcesBuildPhase; 356 | buildActionMask = 2147483647; 357 | files = ( 358 | 4CAC59871DC47F9B00CAA825 /* ic_circle.png in Resources */, 359 | 4CAC59841DC47F9B00CAA825 /* btn_catch.png in Resources */, 360 | 4CAC59861DC47F9B00CAA825 /* ic_arrow.png in Resources */, 361 | 4CAC598A1DC47FB200CAA825 /* bird.gif in Resources */, 362 | 4CAC59441DC47AA800CAA825 /* Assets.xcassets in Resources */, 363 | 4CAC599B1DC4834200CAA825 /* Default-568h@2x.png in Resources */, 364 | 4CAC59881DC47F9B00CAA825 /* ic_circle_normal.png in Resources */, 365 | 4C7AF80D1DC4898300AFA261 /* btn_close_normal@2x.png in Resources */, 366 | 4CAC59851DC47F9B00CAA825 /* btn_catch_normal.png in Resources */, 367 | ); 368 | runOnlyForDeploymentPostprocessing = 0; 369 | }; 370 | 4CAC594B1DC47AA800CAA825 /* Resources */ = { 371 | isa = PBXResourcesBuildPhase; 372 | buildActionMask = 2147483647; 373 | files = ( 374 | ); 375 | runOnlyForDeploymentPostprocessing = 0; 376 | }; 377 | 4CAC59561DC47AA800CAA825 /* Resources */ = { 378 | isa = PBXResourcesBuildPhase; 379 | buildActionMask = 2147483647; 380 | files = ( 381 | ); 382 | runOnlyForDeploymentPostprocessing = 0; 383 | }; 384 | /* End PBXResourcesBuildPhase section */ 385 | 386 | /* Begin PBXSourcesBuildPhase section */ 387 | 4CAC59301DC47AA800CAA825 /* Sources */ = { 388 | isa = PBXSourcesBuildPhase; 389 | buildActionMask = 2147483647; 390 | files = ( 391 | 4CAC593F1DC47AA800CAA825 /* ViewController.m in Sources */, 392 | 4CAC596F1DC47B9D00CAA825 /* YLGIFImage.m in Sources */, 393 | 4CAC59771DC47CE100CAA825 /* YGGravity.m in Sources */, 394 | 4CAC59701DC47B9D00CAA825 /* YLImageView.m in Sources */, 395 | 4CAC59731DC47BD400CAA825 /* MCCatchRedPacketController.m in Sources */, 396 | 4CAC593C1DC47AA800CAA825 /* AppDelegate.m in Sources */, 397 | 4CAC597A1DC47CFD00CAA825 /* MCCatchView.m in Sources */, 398 | 4CAC59391DC47AA800CAA825 /* main.m in Sources */, 399 | 4CAC597D1DC47D4700CAA825 /* RedPacketView.m in Sources */, 400 | ); 401 | runOnlyForDeploymentPostprocessing = 0; 402 | }; 403 | 4CAC59491DC47AA800CAA825 /* Sources */ = { 404 | isa = PBXSourcesBuildPhase; 405 | buildActionMask = 2147483647; 406 | files = ( 407 | 4CAC59521DC47AA800CAA825 /* MCCatchRedPacketTests.m in Sources */, 408 | ); 409 | runOnlyForDeploymentPostprocessing = 0; 410 | }; 411 | 4CAC59541DC47AA800CAA825 /* Sources */ = { 412 | isa = PBXSourcesBuildPhase; 413 | buildActionMask = 2147483647; 414 | files = ( 415 | 4CAC595D1DC47AA800CAA825 /* MCCatchRedPacketUITests.m in Sources */, 416 | ); 417 | runOnlyForDeploymentPostprocessing = 0; 418 | }; 419 | /* End PBXSourcesBuildPhase section */ 420 | 421 | /* Begin PBXTargetDependency section */ 422 | 4CAC594F1DC47AA800CAA825 /* PBXTargetDependency */ = { 423 | isa = PBXTargetDependency; 424 | target = 4CAC59331DC47AA800CAA825 /* MCCatchRedPacket */; 425 | targetProxy = 4CAC594E1DC47AA800CAA825 /* PBXContainerItemProxy */; 426 | }; 427 | 4CAC595A1DC47AA800CAA825 /* PBXTargetDependency */ = { 428 | isa = PBXTargetDependency; 429 | target = 4CAC59331DC47AA800CAA825 /* MCCatchRedPacket */; 430 | targetProxy = 4CAC59591DC47AA800CAA825 /* PBXContainerItemProxy */; 431 | }; 432 | /* End PBXTargetDependency section */ 433 | 434 | /* Begin XCBuildConfiguration section */ 435 | 4CAC595F1DC47AA800CAA825 /* Debug */ = { 436 | isa = XCBuildConfiguration; 437 | buildSettings = { 438 | ALWAYS_SEARCH_USER_PATHS = NO; 439 | CLANG_ANALYZER_NONNULL = YES; 440 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 441 | CLANG_CXX_LIBRARY = "libc++"; 442 | CLANG_ENABLE_MODULES = YES; 443 | CLANG_ENABLE_OBJC_ARC = YES; 444 | CLANG_WARN_BOOL_CONVERSION = YES; 445 | CLANG_WARN_CONSTANT_CONVERSION = YES; 446 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 447 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 448 | CLANG_WARN_EMPTY_BODY = YES; 449 | CLANG_WARN_ENUM_CONVERSION = YES; 450 | CLANG_WARN_INFINITE_RECURSION = YES; 451 | CLANG_WARN_INT_CONVERSION = YES; 452 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 453 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 454 | CLANG_WARN_UNREACHABLE_CODE = YES; 455 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 456 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 457 | COPY_PHASE_STRIP = NO; 458 | DEBUG_INFORMATION_FORMAT = dwarf; 459 | ENABLE_STRICT_OBJC_MSGSEND = YES; 460 | ENABLE_TESTABILITY = YES; 461 | GCC_C_LANGUAGE_STANDARD = gnu99; 462 | GCC_DYNAMIC_NO_PIC = NO; 463 | GCC_NO_COMMON_BLOCKS = YES; 464 | GCC_OPTIMIZATION_LEVEL = 0; 465 | GCC_PREPROCESSOR_DEFINITIONS = ( 466 | "DEBUG=1", 467 | "$(inherited)", 468 | ); 469 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 470 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 471 | GCC_WARN_UNDECLARED_SELECTOR = YES; 472 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 473 | GCC_WARN_UNUSED_FUNCTION = YES; 474 | GCC_WARN_UNUSED_VARIABLE = YES; 475 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 476 | MTL_ENABLE_DEBUG_INFO = YES; 477 | ONLY_ACTIVE_ARCH = YES; 478 | SDKROOT = iphoneos; 479 | }; 480 | name = Debug; 481 | }; 482 | 4CAC59601DC47AA800CAA825 /* Release */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ALWAYS_SEARCH_USER_PATHS = NO; 486 | CLANG_ANALYZER_NONNULL = YES; 487 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 488 | CLANG_CXX_LIBRARY = "libc++"; 489 | CLANG_ENABLE_MODULES = YES; 490 | CLANG_ENABLE_OBJC_ARC = YES; 491 | CLANG_WARN_BOOL_CONVERSION = YES; 492 | CLANG_WARN_CONSTANT_CONVERSION = YES; 493 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 494 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 495 | CLANG_WARN_EMPTY_BODY = YES; 496 | CLANG_WARN_ENUM_CONVERSION = YES; 497 | CLANG_WARN_INFINITE_RECURSION = YES; 498 | CLANG_WARN_INT_CONVERSION = YES; 499 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 500 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 501 | CLANG_WARN_UNREACHABLE_CODE = YES; 502 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 503 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 504 | COPY_PHASE_STRIP = NO; 505 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 506 | ENABLE_NS_ASSERTIONS = NO; 507 | ENABLE_STRICT_OBJC_MSGSEND = YES; 508 | GCC_C_LANGUAGE_STANDARD = gnu99; 509 | GCC_NO_COMMON_BLOCKS = YES; 510 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 511 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 512 | GCC_WARN_UNDECLARED_SELECTOR = YES; 513 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 514 | GCC_WARN_UNUSED_FUNCTION = YES; 515 | GCC_WARN_UNUSED_VARIABLE = YES; 516 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 517 | MTL_ENABLE_DEBUG_INFO = NO; 518 | SDKROOT = iphoneos; 519 | VALIDATE_PRODUCT = YES; 520 | }; 521 | name = Release; 522 | }; 523 | 4CAC59621DC47AA800CAA825 /* Debug */ = { 524 | isa = XCBuildConfiguration; 525 | buildSettings = { 526 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 527 | DEVELOPMENT_TEAM = 9D44C6L83U; 528 | INFOPLIST_FILE = MCCatchRedPacket/Info.plist; 529 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 530 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 531 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacket; 532 | PRODUCT_NAME = "$(TARGET_NAME)"; 533 | }; 534 | name = Debug; 535 | }; 536 | 4CAC59631DC47AA800CAA825 /* Release */ = { 537 | isa = XCBuildConfiguration; 538 | buildSettings = { 539 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 540 | DEVELOPMENT_TEAM = 9D44C6L83U; 541 | INFOPLIST_FILE = MCCatchRedPacket/Info.plist; 542 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 543 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 544 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacket; 545 | PRODUCT_NAME = "$(TARGET_NAME)"; 546 | }; 547 | name = Release; 548 | }; 549 | 4CAC59651DC47AA800CAA825 /* Debug */ = { 550 | isa = XCBuildConfiguration; 551 | buildSettings = { 552 | BUNDLE_LOADER = "$(TEST_HOST)"; 553 | INFOPLIST_FILE = MCCatchRedPacketTests/Info.plist; 554 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 555 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacketTests; 556 | PRODUCT_NAME = "$(TARGET_NAME)"; 557 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MCCatchRedPacket.app/MCCatchRedPacket"; 558 | }; 559 | name = Debug; 560 | }; 561 | 4CAC59661DC47AA800CAA825 /* Release */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | BUNDLE_LOADER = "$(TEST_HOST)"; 565 | INFOPLIST_FILE = MCCatchRedPacketTests/Info.plist; 566 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 567 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacketTests; 568 | PRODUCT_NAME = "$(TARGET_NAME)"; 569 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MCCatchRedPacket.app/MCCatchRedPacket"; 570 | }; 571 | name = Release; 572 | }; 573 | 4CAC59681DC47AA800CAA825 /* Debug */ = { 574 | isa = XCBuildConfiguration; 575 | buildSettings = { 576 | INFOPLIST_FILE = MCCatchRedPacketUITests/Info.plist; 577 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 578 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacketUITests; 579 | PRODUCT_NAME = "$(TARGET_NAME)"; 580 | TEST_TARGET_NAME = MCCatchRedPacket; 581 | }; 582 | name = Debug; 583 | }; 584 | 4CAC59691DC47AA800CAA825 /* Release */ = { 585 | isa = XCBuildConfiguration; 586 | buildSettings = { 587 | INFOPLIST_FILE = MCCatchRedPacketUITests/Info.plist; 588 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 589 | PRODUCT_BUNDLE_IDENTIFIER = MC.MCCatchRedPacketUITests; 590 | PRODUCT_NAME = "$(TARGET_NAME)"; 591 | TEST_TARGET_NAME = MCCatchRedPacket; 592 | }; 593 | name = Release; 594 | }; 595 | /* End XCBuildConfiguration section */ 596 | 597 | /* Begin XCConfigurationList section */ 598 | 4CAC592F1DC47AA800CAA825 /* Build configuration list for PBXProject "MCCatchRedPacket" */ = { 599 | isa = XCConfigurationList; 600 | buildConfigurations = ( 601 | 4CAC595F1DC47AA800CAA825 /* Debug */, 602 | 4CAC59601DC47AA800CAA825 /* Release */, 603 | ); 604 | defaultConfigurationIsVisible = 0; 605 | defaultConfigurationName = Release; 606 | }; 607 | 4CAC59611DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacket" */ = { 608 | isa = XCConfigurationList; 609 | buildConfigurations = ( 610 | 4CAC59621DC47AA800CAA825 /* Debug */, 611 | 4CAC59631DC47AA800CAA825 /* Release */, 612 | ); 613 | defaultConfigurationIsVisible = 0; 614 | defaultConfigurationName = Release; 615 | }; 616 | 4CAC59641DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacketTests" */ = { 617 | isa = XCConfigurationList; 618 | buildConfigurations = ( 619 | 4CAC59651DC47AA800CAA825 /* Debug */, 620 | 4CAC59661DC47AA800CAA825 /* Release */, 621 | ); 622 | defaultConfigurationIsVisible = 0; 623 | defaultConfigurationName = Release; 624 | }; 625 | 4CAC59671DC47AA800CAA825 /* Build configuration list for PBXNativeTarget "MCCatchRedPacketUITests" */ = { 626 | isa = XCConfigurationList; 627 | buildConfigurations = ( 628 | 4CAC59681DC47AA800CAA825 /* Debug */, 629 | 4CAC59691DC47AA800CAA825 /* Release */, 630 | ); 631 | defaultConfigurationIsVisible = 0; 632 | defaultConfigurationName = Release; 633 | }; 634 | /* End XCConfigurationList section */ 635 | }; 636 | rootObject = 4CAC592C1DC47AA800CAA825 /* Project object */; 637 | } 638 | --------------------------------------------------------------------------------