├── Classes ├── SampleViewController.h ├── SampleViewController.m ├── SphereViewAppDelegate.h └── SphereViewAppDelegate.m ├── Default-568h@2x.png ├── README.md ├── SphereView-Info.plist ├── SphereView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── SphereView.xccheckout │ └── xcuserdata │ │ ├── cezarsignori.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings │ │ └── heroims.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ ├── cezarsignori.xcuserdatad │ └── xcschemes │ │ ├── SphereView.xcscheme │ │ └── xcschememanagement.plist │ └── heroims.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── SphereView.xcscheme │ └── xcschememanagement.plist ├── SphereView ├── PFAxisDirection.h ├── PFGoldenSectionSpiral.h ├── PFGoldenSectionSpiral.m ├── PFMatrix.h ├── PFMatrixTransform.h ├── PFPoint.h ├── PFRadian.h ├── ZYQSphereView.h └── ZYQSphereView.m ├── SphereView_Prefix.pch └── main.m /Classes/SampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SampleViewController.h 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface SampleViewController : UIViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Classes/SampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SampleViewController.m 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import "SampleViewController.h" 10 | #import "ZYQSphereView.h" 11 | 12 | @interface SampleViewController (){ 13 | ZYQSphereView *sphereView; 14 | NSTimer *timer; 15 | } 16 | 17 | @end 18 | 19 | @implementation SampleViewController 20 | 21 | -(void)dealloc{ 22 | [sphereView release]; 23 | [timer release]; 24 | [super dealloc]; 25 | } 26 | 27 | - (void)viewDidLoad { 28 | [super viewDidLoad]; 29 | 30 | self.view.backgroundColor = [UIColor blackColor]; 31 | 32 | sphereView = [[ZYQSphereView alloc] initWithFrame:CGRectMake(10, 60, 300, 300)]; 33 | sphereView.center=CGPointMake(self.view.center.x, self.view.center.y-30); 34 | NSMutableArray *views = [[NSMutableArray alloc] init]; 35 | for (int i = 0; i < 50; i++) { 36 | UIButton *subV = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; 37 | subV.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100. green:arc4random_uniform(100)/100. blue:arc4random_uniform(100)/100. alpha:1]; 38 | [subV setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal]; 39 | subV.layer.masksToBounds=YES; 40 | subV.layer.cornerRadius=3; 41 | [subV addTarget:self action:@selector(subVClick:) forControlEvents:UIControlEventTouchUpInside]; 42 | [views addObject:subV]; 43 | [subV release]; 44 | } 45 | 46 | [sphereView setItems:views]; 47 | 48 | sphereView.isPanTimerStart=YES; 49 | [views release]; 50 | 51 | [self.view addSubview:sphereView]; 52 | [sphereView timerStart]; 53 | 54 | 55 | UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom]; 56 | btn.frame=CGRectMake((self.view.frame.size.width-120)/2, self.view.frame.size.height-60, 120, 30); 57 | [self.view addSubview:btn]; 58 | btn.backgroundColor=[UIColor whiteColor]; 59 | btn.layer.borderWidth=1; 60 | btn.layer.borderColor=[[UIColor orangeColor] CGColor]; 61 | [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; 62 | [btn setTitle:@"start/stop" forState:UIControlStateNormal]; 63 | btn.selected=NO; 64 | [btn addTarget:self action:@selector(changePF:) forControlEvents:UIControlEventTouchUpInside]; 65 | 66 | } 67 | 68 | -(void)subVClick:(UIButton*)sender{ 69 | NSLog(@"%@",sender.titleLabel.text); 70 | 71 | BOOL isStart=[sphereView isTimerStart]; 72 | 73 | [sphereView timerStop]; 74 | 75 | [UIView animateWithDuration:0.3 animations:^{ 76 | sender.transform=CGAffineTransformMakeScale(1.5, 1.5); 77 | } completion:^(BOOL finished) { 78 | [UIView animateWithDuration:0.2 animations:^{ 79 | sender.transform=CGAffineTransformMakeScale(1, 1); 80 | if (isStart) { 81 | [sphereView timerStart]; 82 | } 83 | }]; 84 | }]; 85 | } 86 | 87 | 88 | 89 | -(void)changePF:(UIButton*)sender{ 90 | if ([sphereView isTimerStart]) { 91 | [sphereView timerStop]; 92 | } 93 | else{ 94 | [sphereView timerStart]; 95 | } 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /Classes/SphereViewAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SphereViewAppDelegate.h 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SampleViewController.h" 11 | 12 | @interface SphereViewSampleAppDelegate : NSObject { 13 | UIWindow *window; 14 | 15 | SampleViewController *viewController; 16 | } 17 | 18 | @property (nonatomic, retain) IBOutlet UIWindow *window; 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /Classes/SphereViewAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // SphereViewAppDelegate.m 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import "SphereViewAppDelegate.h" 10 | 11 | @implementation SphereViewSampleAppDelegate 12 | 13 | @synthesize window; 14 | 15 | 16 | #pragma mark - 17 | #pragma mark Application lifecycle 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 21 | viewController = [[SampleViewController alloc] init]; 22 | viewController.view.backgroundColor=[UIColor whiteColor]; 23 | window.rootViewController=viewController; 24 | // Override point for customization after application launch. 25 | [window makeKeyAndVisible]; 26 | 27 | return YES; 28 | } 29 | 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application { 32 | /* 33 | 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. 34 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 35 | */ 36 | } 37 | 38 | 39 | - (void)applicationDidEnterBackground:(UIApplication *)application { 40 | /* 41 | 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. 42 | If your application supports background execution, called instead of applicationWillTerminate: when the user quits. 43 | */ 44 | } 45 | 46 | 47 | - (void)applicationWillEnterForeground:(UIApplication *)application { 48 | /* 49 | Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. 50 | */ 51 | } 52 | 53 | 54 | - (void)applicationDidBecomeActive:(UIApplication *)application { 55 | /* 56 | 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. 57 | */ 58 | } 59 | 60 | 61 | - (void)applicationWillTerminate:(UIApplication *)application { 62 | /* 63 | Called when the application is about to terminate. 64 | See also applicationDidEnterBackground:. 65 | */ 66 | } 67 | 68 | 69 | #pragma mark - 70 | #pragma mark Memory management 71 | 72 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 73 | /* 74 | Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. 75 | */ 76 | } 77 | 78 | 79 | - (void)dealloc { 80 | [viewController release]; 81 | [window release]; 82 | [super dealloc]; 83 | } 84 | 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heroims/SphereView/19eb38a48bda1903ad975346d200b747004c4fb3/Default-568h@2x.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SphereView 2 | ========== 3 | 4 | 球形3D 标签 类似网易订阅 可放大 缩小 滑动 点击自动旋转 5 | 6 | 把SphereView文件夹拖入项目即可支持arc 非arc 7 | 8 | [![](http://heroims.github.io/SphereView/Untitled1.gif)](http://heroims.github.io/SphereView/Untitled1.gif) 9 | -------------------------------------------------------------------------------- /SphereView-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1D3623260D0F684500981E51 /* SphereViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* SphereViewAppDelegate.m */; }; 11 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; 12 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 13 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; 14 | 288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; }; 15 | 6D09BF1312AC8C8B008D685B /* SampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D09BF1212AC8C8B008D685B /* SampleViewController.m */; }; 16 | D8AC4828184B8BD800E08789 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D8AC4827184B8BD800E08789 /* Default-568h@2x.png */; }; 17 | D8D223861854C3E300EF2DFB /* PFGoldenSectionSpiral.m in Sources */ = {isa = PBXBuildFile; fileRef = D8D2237F1854C3E300EF2DFB /* PFGoldenSectionSpiral.m */; }; 18 | D8D223871854C3E300EF2DFB /* ZYQSphereView.m in Sources */ = {isa = PBXBuildFile; fileRef = D8D223851854C3E300EF2DFB /* ZYQSphereView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 23 | 1D3623240D0F684500981E51 /* SphereViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SphereViewAppDelegate.h; sourceTree = ""; }; 24 | 1D3623250D0F684500981E51 /* SphereViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SphereViewAppDelegate.m; sourceTree = ""; }; 25 | 1D6058910D05DD3D006BFB54 /* SphereView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SphereView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 27 | 288765FC0DF74451002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 28 | 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 29 | 32CA4F630368D1EE00C91783 /* SphereView_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SphereView_Prefix.pch; sourceTree = ""; }; 30 | 6D09BF1112AC8C8B008D685B /* SampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleViewController.h; sourceTree = ""; }; 31 | 6D09BF1212AC8C8B008D685B /* SampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleViewController.m; sourceTree = ""; }; 32 | 8D1107310486CEB800E47090 /* SphereView-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SphereView-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; 33 | D8AC4827184B8BD800E08789 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 34 | D8D2237D1854C3E300EF2DFB /* PFAxisDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFAxisDirection.h; sourceTree = ""; }; 35 | D8D2237E1854C3E300EF2DFB /* PFGoldenSectionSpiral.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFGoldenSectionSpiral.h; sourceTree = ""; }; 36 | D8D2237F1854C3E300EF2DFB /* PFGoldenSectionSpiral.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFGoldenSectionSpiral.m; sourceTree = ""; }; 37 | D8D223801854C3E300EF2DFB /* PFMatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFMatrix.h; sourceTree = ""; }; 38 | D8D223811854C3E300EF2DFB /* PFMatrixTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFMatrixTransform.h; sourceTree = ""; }; 39 | D8D223821854C3E300EF2DFB /* PFPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFPoint.h; sourceTree = ""; }; 40 | D8D223831854C3E300EF2DFB /* PFRadian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFRadian.h; sourceTree = ""; }; 41 | D8D223841854C3E300EF2DFB /* ZYQSphereView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZYQSphereView.h; sourceTree = ""; }; 42 | D8D223851854C3E300EF2DFB /* ZYQSphereView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZYQSphereView.m; sourceTree = ""; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | 1D60588F0D05DD3D006BFB54 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, 51 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, 52 | 288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */, 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | 080E96DDFE201D6D7F000001 /* Classes */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | 1D3623240D0F684500981E51 /* SphereViewAppDelegate.h */, 63 | 1D3623250D0F684500981E51 /* SphereViewAppDelegate.m */, 64 | 6D09BF1112AC8C8B008D685B /* SampleViewController.h */, 65 | 6D09BF1212AC8C8B008D685B /* SampleViewController.m */, 66 | ); 67 | path = Classes; 68 | sourceTree = ""; 69 | }; 70 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 1D6058910D05DD3D006BFB54 /* SphereView.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | D8AC4827184B8BD800E08789 /* Default-568h@2x.png */, 82 | D8D2237C1854C3E300EF2DFB /* SphereView */, 83 | 080E96DDFE201D6D7F000001 /* Classes */, 84 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 85 | 29B97317FDCFA39411CA2CEA /* Resources */, 86 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 87 | 19C28FACFE9D520D11CA2CBB /* Products */, 88 | ); 89 | name = CustomTemplate; 90 | sourceTree = ""; 91 | }; 92 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 32CA4F630368D1EE00C91783 /* SphereView_Prefix.pch */, 96 | 29B97316FDCFA39411CA2CEA /* main.m */, 97 | ); 98 | name = "Other Sources"; 99 | sourceTree = ""; 100 | }; 101 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 8D1107310486CEB800E47090 /* SphereView-Info.plist */, 105 | ); 106 | name = Resources; 107 | sourceTree = ""; 108 | }; 109 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 113 | 1D30AB110D05D00D00671497 /* Foundation.framework */, 114 | 288765FC0DF74451002DB57D /* CoreGraphics.framework */, 115 | ); 116 | name = Frameworks; 117 | sourceTree = ""; 118 | }; 119 | D8D2237C1854C3E300EF2DFB /* SphereView */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | D8D2237D1854C3E300EF2DFB /* PFAxisDirection.h */, 123 | D8D2237E1854C3E300EF2DFB /* PFGoldenSectionSpiral.h */, 124 | D8D2237F1854C3E300EF2DFB /* PFGoldenSectionSpiral.m */, 125 | D8D223801854C3E300EF2DFB /* PFMatrix.h */, 126 | D8D223811854C3E300EF2DFB /* PFMatrixTransform.h */, 127 | D8D223821854C3E300EF2DFB /* PFPoint.h */, 128 | D8D223831854C3E300EF2DFB /* PFRadian.h */, 129 | D8D223841854C3E300EF2DFB /* ZYQSphereView.h */, 130 | D8D223851854C3E300EF2DFB /* ZYQSphereView.m */, 131 | ); 132 | path = SphereView; 133 | sourceTree = ""; 134 | }; 135 | /* End PBXGroup section */ 136 | 137 | /* Begin PBXNativeTarget section */ 138 | 1D6058900D05DD3D006BFB54 /* SphereView */ = { 139 | isa = PBXNativeTarget; 140 | buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "SphereView" */; 141 | buildPhases = ( 142 | 1D60588D0D05DD3D006BFB54 /* Resources */, 143 | 1D60588E0D05DD3D006BFB54 /* Sources */, 144 | 1D60588F0D05DD3D006BFB54 /* Frameworks */, 145 | ); 146 | buildRules = ( 147 | ); 148 | dependencies = ( 149 | ); 150 | name = SphereView; 151 | productName = SphereView; 152 | productReference = 1D6058910D05DD3D006BFB54 /* SphereView.app */; 153 | productType = "com.apple.product-type.application"; 154 | }; 155 | /* End PBXNativeTarget section */ 156 | 157 | /* Begin PBXProject section */ 158 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 159 | isa = PBXProject; 160 | attributes = { 161 | LastUpgradeCheck = 0500; 162 | }; 163 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SphereView" */; 164 | compatibilityVersion = "Xcode 3.2"; 165 | developmentRegion = English; 166 | hasScannedForEncodings = 1; 167 | knownRegions = ( 168 | English, 169 | Japanese, 170 | French, 171 | German, 172 | ); 173 | mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; 174 | projectDirPath = ""; 175 | projectRoot = ""; 176 | targets = ( 177 | 1D6058900D05DD3D006BFB54 /* SphereView */, 178 | ); 179 | }; 180 | /* End PBXProject section */ 181 | 182 | /* Begin PBXResourcesBuildPhase section */ 183 | 1D60588D0D05DD3D006BFB54 /* Resources */ = { 184 | isa = PBXResourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | D8AC4828184B8BD800E08789 /* Default-568h@2x.png in Resources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXResourcesBuildPhase section */ 192 | 193 | /* Begin PBXSourcesBuildPhase section */ 194 | 1D60588E0D05DD3D006BFB54 /* Sources */ = { 195 | isa = PBXSourcesBuildPhase; 196 | buildActionMask = 2147483647; 197 | files = ( 198 | D8D223871854C3E300EF2DFB /* ZYQSphereView.m in Sources */, 199 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, 200 | D8D223861854C3E300EF2DFB /* PFGoldenSectionSpiral.m in Sources */, 201 | 1D3623260D0F684500981E51 /* SphereViewAppDelegate.m in Sources */, 202 | 6D09BF1312AC8C8B008D685B /* SampleViewController.m in Sources */, 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | }; 206 | /* End PBXSourcesBuildPhase section */ 207 | 208 | /* Begin XCBuildConfiguration section */ 209 | 1D6058940D05DD3E006BFB54 /* Debug */ = { 210 | isa = XCBuildConfiguration; 211 | buildSettings = { 212 | ALWAYS_SEARCH_USER_PATHS = NO; 213 | COPY_PHASE_STRIP = NO; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_OPTIMIZATION_LEVEL = 0; 216 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 217 | GCC_PREFIX_HEADER = SphereView_Prefix.pch; 218 | INFOPLIST_FILE = "SphereView-Info.plist"; 219 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 220 | PRODUCT_NAME = SphereView; 221 | PROVISIONING_PROFILE = "6AACA49D-3C66-4565-B975-52322449A8EC"; 222 | }; 223 | name = Debug; 224 | }; 225 | 1D6058950D05DD3E006BFB54 /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | COPY_PHASE_STRIP = YES; 230 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 231 | GCC_PREFIX_HEADER = SphereView_Prefix.pch; 232 | INFOPLIST_FILE = "SphereView-Info.plist"; 233 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 234 | PRODUCT_NAME = SphereView; 235 | PROVISIONING_PROFILE = "6AACA49D-3C66-4565-B975-52322449A8EC"; 236 | VALIDATE_PRODUCT = YES; 237 | }; 238 | name = Release; 239 | }; 240 | C01FCF4F08A954540054247B /* Debug */ = { 241 | isa = XCBuildConfiguration; 242 | buildSettings = { 243 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 244 | GCC_C_LANGUAGE_STANDARD = c99; 245 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 248 | ONLY_ACTIVE_ARCH = YES; 249 | SDKROOT = iphoneos; 250 | }; 251 | name = Debug; 252 | }; 253 | C01FCF5008A954540054247B /* Release */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | GCC_C_LANGUAGE_STANDARD = c99; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 4.3; 261 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 262 | SDKROOT = iphoneos; 263 | }; 264 | name = Release; 265 | }; 266 | /* End XCBuildConfiguration section */ 267 | 268 | /* Begin XCConfigurationList section */ 269 | 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "SphereView" */ = { 270 | isa = XCConfigurationList; 271 | buildConfigurations = ( 272 | 1D6058940D05DD3E006BFB54 /* Debug */, 273 | 1D6058950D05DD3E006BFB54 /* Release */, 274 | ); 275 | defaultConfigurationIsVisible = 0; 276 | defaultConfigurationName = Release; 277 | }; 278 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SphereView" */ = { 279 | isa = XCConfigurationList; 280 | buildConfigurations = ( 281 | C01FCF4F08A954540054247B /* Debug */, 282 | C01FCF5008A954540054247B /* Release */, 283 | ); 284 | defaultConfigurationIsVisible = 0; 285 | defaultConfigurationName = Release; 286 | }; 287 | /* End XCConfigurationList section */ 288 | }; 289 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 290 | } 291 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/xcshareddata/SphereView.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | AE845D68-A376-44B9-98BD-A0345A4FC3BC 9 | IDESourceControlProjectName 10 | SphereView 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | FF758BAB-4443-40EA-BF37-0D7690E5F039 14 | https://github.com/heroims/SphereView.git 15 | 16 | IDESourceControlProjectPath 17 | SphereView.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | FF758BAB-4443-40EA-BF37-0D7690E5F039 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/heroims/SphereView.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | FF758BAB-4443-40EA-BF37-0D7690E5F039 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | FF758BAB-4443-40EA-BF37-0D7690E5F039 36 | IDESourceControlWCCName 37 | SphereView 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/xcuserdata/cezarsignori.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heroims/SphereView/19eb38a48bda1903ad975346d200b747004c4fb3/SphereView.xcodeproj/project.xcworkspace/xcuserdata/cezarsignori.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/xcuserdata/cezarsignori.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/xcuserdata/heroims.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heroims/SphereView/19eb38a48bda1903ad975346d200b747004c4fb3/SphereView.xcodeproj/project.xcworkspace/xcuserdata/heroims.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SphereView.xcodeproj/project.xcworkspace/xcuserdata/heroims.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/xcuserdata/cezarsignori.xcuserdatad/xcschemes/SphereView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 49 | 50 | 56 | 57 | 58 | 59 | 60 | 61 | 67 | 68 | 74 | 75 | 76 | 77 | 79 | 80 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/xcuserdata/cezarsignori.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SphereView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1D6058900D05DD3D006BFB54 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/xcuserdata/heroims.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/xcuserdata/heroims.xcuserdatad/xcschemes/SphereView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /SphereView.xcodeproj/xcuserdata/heroims.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SphereView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1D6058900D05DD3D006BFB54 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SphereView/PFAxisDirection.h: -------------------------------------------------------------------------------- 1 | //This file is part of SphereView. 2 | // 3 | //SphereView is free software: you can redistribute it and/or modify 4 | //it under the terms of the GNU General Public License as published by 5 | //the Free Software Foundation, either version 3 of the License, or 6 | //(at your option) any later version. 7 | // 8 | //SphereView is distributed in the hope that it will be useful, 9 | //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | //GNU General Public License for more details. 12 | // 13 | //You should have received a copy of the GNU General Public License 14 | //along with SphereView. If not, see . 15 | 16 | typedef enum { 17 | PFAxisDirectionNone, 18 | PFAxisDirectionPositive = 1, 19 | PFAxisDirectionNegative = -1 20 | } PFAxisDirection; 21 | 22 | static CGFloat PFAxisDirectionMinimumDistance = 0.033f; 23 | 24 | static PFAxisDirection PFAxisDirectionMake(CGFloat fromCoordinate, CGFloat toCoordinate, BOOL sensitive) { 25 | PFAxisDirection direction = PFAxisDirectionNone; 26 | 27 | CGFloat distance = fabs(fromCoordinate - toCoordinate); 28 | 29 | if (distance > PFAxisDirectionMinimumDistance || sensitive) { 30 | if (fromCoordinate > toCoordinate) { 31 | direction = PFAxisDirectionPositive; 32 | } else if (fromCoordinate < toCoordinate) { 33 | direction = PFAxisDirectionNegative; 34 | } 35 | } 36 | 37 | return direction; 38 | } 39 | 40 | static PFAxisDirection PFDirectionMakeXAxis(CGPoint fromPoint, CGPoint toPoint) { 41 | return PFAxisDirectionMake(fromPoint.x, toPoint.x, NO); 42 | } 43 | 44 | static PFAxisDirection PFDirectionMakeYAxis(CGPoint fromPoint, CGPoint toPoint) { 45 | return PFAxisDirectionMake(fromPoint.y, toPoint.y, NO); 46 | } 47 | 48 | static PFAxisDirection PFDirectionMakeXAxisSensitive(CGPoint fromPoint, CGPoint toPoint) { 49 | return PFAxisDirectionMake(fromPoint.x, toPoint.x, YES); 50 | } 51 | 52 | static PFAxisDirection PFDirectionMakeYAxisSensitive(CGPoint fromPoint, CGPoint toPoint) { 53 | return PFAxisDirectionMake(fromPoint.y, toPoint.y, YES); 54 | } -------------------------------------------------------------------------------- /SphereView/PFGoldenSectionSpiral.h: -------------------------------------------------------------------------------- 1 | //This file is part of SphereView. 2 | // 3 | //SphereView is free software: you can redistribute it and/or modify 4 | //it under the terms of the GNU General Public License as published by 5 | //the Free Software Foundation, either version 3 of the License, or 6 | //(at your option) any later version. 7 | // 8 | //SphereView is distributed in the hope that it will be useful, 9 | //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | //GNU General Public License for more details. 12 | // 13 | //You should have received a copy of the GNU General Public License 14 | //along with SphereView. If not, see . 15 | 16 | #import 17 | 18 | // Parfait 19 | #import "PFRadian.h" 20 | #import "PFPoint.h" 21 | #import "PFMatrix.h" 22 | #import "PFMatrixTransform.h" 23 | 24 | @interface PFGoldenSectionSpiral : NSObject { 25 | 26 | } 27 | 28 | + (NSArray *)sphere:(NSInteger)n; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /SphereView/PFGoldenSectionSpiral.m: -------------------------------------------------------------------------------- 1 | //This file is part of SphereView. 2 | // 3 | //SphereView is free software: you can redistribute it and/or modify 4 | //it under the terms of the GNU General Public License as published by 5 | //the Free Software Foundation, either version 3 of the License, or 6 | //(at your option) any later version. 7 | // 8 | //SphereView is distributed in the hope that it will be useful, 9 | //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | //GNU General Public License for more details. 12 | // 13 | //You should have received a copy of the GNU General Public License 14 | //along with SphereView. If not, see . 15 | 16 | #import "PFGoldenSectionSpiral.h" 17 | 18 | @implementation PFGoldenSectionSpiral 19 | 20 | + (NSArray *)sphere:(NSInteger)n { 21 | NSMutableArray* result = [NSMutableArray arrayWithCapacity:n]; 22 | 23 | CGFloat N = n; 24 | CGFloat inc = M_PI * (3 - sqrt(5)); 25 | CGFloat off = 2 / N; 26 | for (NSInteger k=0; k. 15 | 16 | #define PFMatrixMaxSize 4 17 | 18 | struct PFMatrix { 19 | NSInteger m; 20 | NSInteger n; 21 | 22 | CGFloat data[PFMatrixMaxSize][PFMatrixMaxSize]; 23 | }; 24 | typedef struct PFMatrix PFMatrix; 25 | 26 | static PFMatrix PFMatrixMake(NSInteger m, NSInteger n) { 27 | PFMatrix matrix; 28 | matrix.m = m; 29 | matrix.n = n; 30 | 31 | for(NSInteger i=0; i. 15 | 16 | static PFMatrix PFMatrixTransform3DMakeFromPFPoint(PFPoint point) { 17 | CGFloat pointRef[1][4] = {{point.x, point.y, point.z, 1}}; 18 | 19 | PFMatrix matrix = PFMatrixMakeFromArray(1, 4, *pointRef); 20 | 21 | return matrix; 22 | } 23 | 24 | static PFMatrix PFMatrixTransform3DMakeTranslation(PFPoint point) { 25 | CGFloat T[4][4] = { 26 | {1, 0, 0, 0}, 27 | {0, 1, 0, 0}, 28 | {0, 0, 1, 0}, 29 | {point.x, point.y, point.z, 1} 30 | }; 31 | 32 | PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T); 33 | 34 | return matrix; 35 | } 36 | 37 | static PFMatrix PFMatrixTransform3DMakeXRotation(PFRadian angle) { 38 | CGFloat c = cos(PFRadianMake(angle)); 39 | CGFloat s = sin(PFRadianMake(angle)); 40 | 41 | CGFloat T[4][4] = { 42 | {1, 0, 0, 0}, 43 | {0, c, s, 0}, 44 | {0, -s, c, 0}, 45 | {0, 0, 0, 1} 46 | }; 47 | 48 | PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T); 49 | 50 | return matrix; 51 | } 52 | 53 | static PFMatrix PFMatrixTransform3DMakeXRotationOnPoint(PFPoint point, PFRadian angle) { 54 | PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z)); 55 | PFMatrix R = PFMatrixTransform3DMakeXRotation(angle); 56 | PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point); 57 | 58 | return PFMatrixMultiply(PFMatrixMultiply(T, R), T1); 59 | } 60 | 61 | static PFMatrix PFMatrixTransform3DMakeYRotation(PFRadian angle) { 62 | CGFloat c = cos(PFRadianMake(angle)); 63 | CGFloat s = sin(PFRadianMake(angle)); 64 | 65 | CGFloat T[4][4] = { 66 | {c, 0, -s, 0}, 67 | {0, 1, 0, 0}, 68 | {s, 0, c, 0}, 69 | {0, 0, 0, 1} 70 | }; 71 | 72 | PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T); 73 | 74 | return matrix; 75 | } 76 | 77 | static PFMatrix PFMatrixTransform3DMakeYRotationOnPoint(PFPoint point, PFRadian angle) { 78 | PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z)); 79 | PFMatrix R = PFMatrixTransform3DMakeYRotation(angle); 80 | PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point); 81 | 82 | return PFMatrixMultiply(PFMatrixMultiply(T, R), T1); 83 | } 84 | 85 | static PFMatrix PFMatrixTransform3DMakeZRotation(PFRadian angle) { 86 | CGFloat c = cos(PFRadianMake(angle)); 87 | CGFloat s = sin(PFRadianMake(angle)); 88 | 89 | CGFloat T[4][4] = { 90 | {c, s, 0, 0}, 91 | {-s, c, 0, 0}, 92 | {0, 0, 1, 0}, 93 | {0, 0, 0, 1} 94 | }; 95 | 96 | PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T); 97 | 98 | return matrix; 99 | } 100 | 101 | static PFMatrix PFMatrixTransform3DMakeZRotationOnPoint(PFPoint point, PFRadian angle) { 102 | PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z)); 103 | PFMatrix R = PFMatrixTransform3DMakeZRotation(angle); 104 | PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point); 105 | 106 | return PFMatrixMultiply(PFMatrixMultiply(T, R), T1); 107 | } -------------------------------------------------------------------------------- /SphereView/PFPoint.h: -------------------------------------------------------------------------------- 1 | //This file is part of SphereView. 2 | // 3 | //SphereView is free software: you can redistribute it and/or modify 4 | //it under the terms of the GNU General Public License as published by 5 | //the Free Software Foundation, either version 3 of the License, or 6 | //(at your option) any later version. 7 | // 8 | //SphereView is distributed in the hope that it will be useful, 9 | //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | //GNU General Public License for more details. 12 | // 13 | //You should have received a copy of the GNU General Public License 14 | //along with SphereView. If not, see . 15 | 16 | #import "PFMatrix.h" 17 | 18 | struct PFPoint { 19 | CGFloat x; 20 | CGFloat y; 21 | CGFloat z; 22 | }; 23 | typedef struct PFPoint PFPoint; 24 | 25 | static PFPoint PFPointMake(CGFloat x, CGFloat y, CGFloat z) { 26 | PFPoint p; 27 | p.x = x; 28 | p.y = y; 29 | p.z = z; 30 | 31 | return p; 32 | } 33 | 34 | static PFPoint PFPointMakeFromMatrix(PFMatrix matrix) { 35 | return PFPointMake(matrix.data[0][0], matrix.data[0][1], matrix.data[0][2]); 36 | } 37 | 38 | static NSString *NSStringFromPFPoint(PFPoint point) { 39 | NSString *str = [NSString stringWithFormat:@"(%f,%f,%f)", point.x, point.y, point.z]; 40 | 41 | return str; 42 | } 43 | 44 | 45 | #pragma mark - 46 | #pragma mark CGPoint methods 47 | 48 | static CGPoint CGPointMakeNormalizedPoint(CGPoint point, CGFloat distance) { 49 | CGPoint nPoint = CGPointMake(point.x * 1/distance, point.y * 1/distance); 50 | 51 | return nPoint; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /SphereView/PFRadian.h: -------------------------------------------------------------------------------- 1 | //This file is part of SphereView. 2 | // 3 | //SphereView is free software: you can redistribute it and/or modify 4 | //it under the terms of the GNU General Public License as published by 5 | //the Free Software Foundation, either version 3 of the License, or 6 | //(at your option) any later version. 7 | // 8 | //SphereView is distributed in the hope that it will be useful, 9 | //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | //GNU General Public License for more details. 12 | // 13 | //You should have received a copy of the GNU General Public License 14 | //along with SphereView. If not, see . 15 | 16 | typedef CGFloat PFRadian; 17 | 18 | static PFRadian PFRadianMake(CGFloat grades) { 19 | return (M_PI * grades / 180.0); 20 | } 21 | -------------------------------------------------------------------------------- /SphereView/ZYQSphereView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZYQSphereView.h 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import "PFAxisDirection.h" 10 | 11 | @interface ZYQSphereView : UIView { 12 | NSMutableDictionary *pointMap; 13 | 14 | CGPoint originalLocationInView; 15 | CGPoint previousLocationInView; 16 | 17 | PFAxisDirection lastXAxisDirection; 18 | PFAxisDirection lastYAxisDirection; 19 | 20 | CGRect originalSphereViewBounds; 21 | } 22 | 23 | @property(nonatomic,assign)BOOL isPanTimerStart; 24 | @property(nonatomic,getter = isTimerStart,readonly)BOOL isTimerStart; 25 | 26 | - (void)setItems:(NSArray *)items; 27 | 28 | -(void)timerStart; 29 | 30 | -(void)timerStop; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /SphereView/ZYQSphereView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ZYQSphereView.m 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import "ZYQSphereView.h" 10 | #import "PFGoldenSectionSpiral.h" 11 | #import 12 | 13 | @interface ZYQSphereView(Private) 14 | - (CGFloat)coordinateForNormalizedValue:(CGFloat)normalizedValue withinRangeOffset:(CGFloat)rangeOffset; 15 | - (void)rotateSphereByAngle:(CGFloat)angle fromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint; 16 | - (void)layoutViews; 17 | - (void)layoutView:(UIView *)view withPoint:(PFPoint)point; 18 | @end 19 | 20 | @interface ZYQSphereView (){ 21 | float intervalX; 22 | float intervalY; 23 | } 24 | 25 | @property(nonatomic,strong)NSTimer *timer; 26 | 27 | @end 28 | 29 | @implementation ZYQSphereView 30 | 31 | -(BOOL)isTimerStart{ 32 | return [_timer isValid]; 33 | } 34 | 35 | - (id)initWithFrame:(CGRect)frame { 36 | if ((self = [super initWithFrame:frame])) { 37 | UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; 38 | panRecognizer.minimumNumberOfTouches = 1; 39 | [self addGestureRecognizer:panRecognizer]; 40 | #if __has_feature(objc_arc) 41 | #else 42 | [panRecognizer release]; 43 | #endif 44 | 45 | UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)]; 46 | [self addGestureRecognizer:pinchRecognizer]; 47 | #if __has_feature(objc_arc) 48 | #else 49 | [pinchRecognizer release]; 50 | #endif 51 | 52 | UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationGesture:)]; 53 | [self addGestureRecognizer:rotationRecognizer]; 54 | #if __has_feature(objc_arc) 55 | #else 56 | [rotationRecognizer release]; 57 | #endif 58 | 59 | UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; 60 | tapRecognizer.numberOfTapsRequired = 1; 61 | [self addGestureRecognizer:tapRecognizer]; 62 | #if __has_feature(objc_arc) 63 | #else 64 | [tapRecognizer release]; 65 | #endif 66 | 67 | intervalX=1; 68 | } 69 | return self; 70 | } 71 | 72 | -(void)changeView{ 73 | CGPoint normalPoint=self.frame.origin; 74 | CGPoint movePoint=CGPointMake(self.frame.origin.x+intervalX, self.frame.origin.y+intervalY); 75 | 76 | [self rotateSphereByAngle:1 fromPoint:normalPoint toPoint:movePoint]; 77 | } 78 | 79 | -(void)timerStart{ 80 | if (_timer.isValid) { 81 | [_timer invalidate]; 82 | } 83 | self.timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeView) userInfo:nil repeats:YES]; 84 | } 85 | 86 | -(void)timerStop{ 87 | if (_timer.isValid) { 88 | [_timer invalidate]; 89 | } 90 | } 91 | 92 | - (void)setItems:(NSArray *)items { 93 | #if __has_feature(objc_arc) 94 | #else 95 | [pointMap release]; 96 | #endif 97 | pointMap = [[NSMutableDictionary alloc] init]; 98 | 99 | NSArray *spherePoints = [PFGoldenSectionSpiral sphere:items.count]; 100 | for (int i=0; i screenFrame.size.width 191 | && sphereFrame.size.height > screenFrame.size.height) 192 | || (sphereFrame.size.width < originalSphereViewBounds.size.width 193 | && sphereFrame.size.height < originalSphereViewBounds.size.height)) { 194 | return; 195 | } 196 | 197 | view.bounds = sphereFrame; 198 | 199 | 200 | [self layoutViews]; 201 | } 202 | 203 | - (void)handleRotationGesture:(UIRotationGestureRecognizer *)rotationRecognizer { 204 | static CGFloat LastSphereRotationAngle; 205 | 206 | if (rotationRecognizer.state == UIGestureRecognizerStateEnded) { 207 | LastSphereRotationAngle = 0; 208 | return; 209 | } 210 | 211 | PFAxisDirection rotationDirection; 212 | 213 | CGFloat rotation = rotationRecognizer.rotation; 214 | 215 | if (rotation > LastSphereRotationAngle) { 216 | rotationDirection = PFAxisDirectionPositive; 217 | } else if (rotation < LastSphereRotationAngle) { 218 | rotationDirection = PFAxisDirectionNegative; 219 | } 220 | 221 | rotation = fabs(rotation) * rotationDirection; 222 | 223 | NSArray *subviews = self.subviews; 224 | for (int i=0; i 0) { 300 | coordinate += half; 301 | } else { 302 | coordinate = half - coordinate; 303 | } 304 | return coordinate; 305 | } 306 | 307 | - (void)layoutView:(UIView *)view withPoint:(PFPoint)point { 308 | CGFloat viewSize = view.frame.size.width; 309 | 310 | CGFloat width = self.frame.size.width - viewSize*2; 311 | CGFloat x = [self coordinateForNormalizedValue:point.x withinRangeOffset:width]; 312 | CGFloat y = [self coordinateForNormalizedValue:point.y withinRangeOffset:width]; 313 | view.center = CGPointMake(x + viewSize, y + viewSize); 314 | 315 | CGFloat z = [self coordinateForNormalizedValue:point.z withinRangeOffset:1]; 316 | 317 | view.transform = CGAffineTransformScale(CGAffineTransformIdentity, z, z); 318 | view.layer.zPosition = z; 319 | } 320 | 321 | - (void)layoutViews { 322 | NSArray *subviews = self.subviews; 323 | for (int i=0; i 11 | #import 12 | #endif 13 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SphereViewSample 4 | // 5 | // Created by Zhao Yiqi on 13-12-8. 6 | // Copyright (c) 2013年 Zhao Yiqi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, @"SphereViewSampleAppDelegate"); 15 | [pool release]; 16 | return retVal; 17 | } 18 | --------------------------------------------------------------------------------