├── .gitignore ├── BSPanorama.gif ├── BSPanoramaView.podspec ├── BSPanoramaView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── BSPanoramaView ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── placeholder.imageset │ │ ├── Contents.json │ │ └── WechatIMG130.png │ └── test.imageset │ │ ├── Contents.json │ │ └── test-2.png ├── BSPanoramaView.h ├── BSPanoramaView.m ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── PanoTableViewCell.h ├── PanoTableViewCell.m ├── SinglePanoViewController.h ├── SinglePanoViewController.m ├── TablePanoViewController.h ├── TablePanoViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── Chinese.md ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /BSPanorama.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestswifter/BSPanoramaView/cc41ef1efe458f3d55ae97db63fb9434aa19245d/BSPanorama.gif -------------------------------------------------------------------------------- /BSPanoramaView.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint BSPanoramaView.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | s.name = "BSPanoramaView" 19 | s.version = "0.0.3" 20 | s.summary = "A lightweight panorama view browser on iOS platform" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | s.description = "Most third-party framework is too large to be put into an app, I write this pod because I only need to show a panorama picture." 28 | 29 | s.homepage = "https://github.com/bestswifter/BSPanoramaView" 30 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 31 | 32 | 33 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 34 | # 35 | # Licensing your code is important. See http://choosealicense.com for more info. 36 | # CocoaPods will detect a license file if there is a named LICENSE* 37 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 38 | # 39 | 40 | s.license = "GPL 3.0" 41 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 42 | 43 | 44 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 45 | # 46 | # Specify the authors of the library, with email addresses. Email addresses 47 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 48 | # accepts just a name if you'd rather not provide an email address. 49 | # 50 | # Specify a social_media_url where others can refer to, for example a twitter 51 | # profile URL. 52 | # 53 | 54 | s.author = { "bestswifter" => "ktzhang@bestswifter.com" } 55 | # Or just: s.author = "zhangxingyu" 56 | # s.authors = { "zhangxingyu" => "zhangxingyu@baidu.com" } 57 | # s.social_media_url = "http://twitter.com/zhangxingyu" 58 | 59 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 60 | # 61 | # If this Pod runs only on iOS or OS X, then specify the platform and 62 | # the deployment target. You can optionally include the target after the platform. 63 | # 64 | 65 | s.platform = :ios 66 | # s.platform = :ios, "5.0" 67 | 68 | # When using multiple platforms 69 | # s.ios.deployment_target = "5.0" 70 | # s.osx.deployment_target = "10.7" 71 | # s.watchos.deployment_target = "2.0" 72 | # s.tvos.deployment_target = "9.0" 73 | 74 | 75 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 76 | # 77 | # Specify the location from where the source should be retrieved. 78 | # Supports git, hg, bzr, svn and HTTP. 79 | # 80 | 81 | s.source = { :git => "https://github.com/bestswifter/BSPanoramaView.git", :tag => "#{s.version}" } 82 | 83 | 84 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 85 | # 86 | # CocoaPods is smart about how it includes source code. For source files 87 | # giving a folder will include any swift, h, m, mm, c & cpp files. 88 | # For header files it will include any header in the folder. 89 | # Not including the public_header_files will make all headers public. 90 | # 91 | 92 | s.source_files = "BSPanoramaView/BSPanoramaView.{h,m}" 93 | # s.public_header_files = "Classes/**/*.h" 94 | 95 | 96 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 97 | # 98 | # A list of resources included with the Pod. These are copied into the 99 | # target bundle with a build phase script. Anything else will be cleaned. 100 | # You can preserve files from being cleaned, please don't preserve 101 | # non-essential files like tests, examples and documentation. 102 | # 103 | 104 | # s.resource = "icon.png" 105 | # s.resources = "Resources/*.png" 106 | 107 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 108 | 109 | 110 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 111 | # 112 | # Link your library with frameworks, or libraries. Libraries do not include 113 | # the lib prefix of their name. 114 | # 115 | 116 | # s.framework = "SomeFramework" 117 | # s.frameworks = "SomeFramework", "AnotherFramework" 118 | s.frameworks = "GLKit", "CoreMotion" 119 | 120 | # s.library = "iconv" 121 | # s.libraries = "iconv", "xml2" 122 | 123 | 124 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 125 | # 126 | # If your library depends on compiler flags you can set them in the xcconfig hash 127 | # where they will only apply to your library. If you depend on other Podspecs 128 | # you can include multiple dependencies to ensure it works. 129 | 130 | # s.requires_arc = true 131 | 132 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 133 | # s.dependency "JSONKit", "~> 1.4" 134 | 135 | end 136 | -------------------------------------------------------------------------------- /BSPanoramaView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9B9E00B91FBC29B600DB85C6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00B81FBC29B600DB85C6 /* AppDelegate.m */; }; 11 | 9B9E00BC1FBC29B600DB85C6 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00BB1FBC29B600DB85C6 /* ViewController.m */; }; 12 | 9B9E00BF1FBC29B600DB85C6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9B9E00BD1FBC29B600DB85C6 /* Main.storyboard */; }; 13 | 9B9E00C11FBC29B600DB85C6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9B9E00C01FBC29B600DB85C6 /* Assets.xcassets */; }; 14 | 9B9E00C41FBC29B600DB85C6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9B9E00C21FBC29B600DB85C6 /* LaunchScreen.storyboard */; }; 15 | 9B9E00C71FBC29B600DB85C6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00C61FBC29B600DB85C6 /* main.m */; }; 16 | 9B9E00CF1FBC29E300DB85C6 /* BSPanoramaView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00CE1FBC29E300DB85C6 /* BSPanoramaView.m */; }; 17 | 9B9E00D21FBC32C300DB85C6 /* SinglePanoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00D11FBC32C300DB85C6 /* SinglePanoViewController.m */; }; 18 | 9B9E00D51FBC36F900DB85C6 /* TablePanoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00D41FBC36F900DB85C6 /* TablePanoViewController.m */; }; 19 | 9B9E00D81FBC380600DB85C6 /* PanoTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9E00D61FBC380500DB85C6 /* PanoTableViewCell.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 9B9E00B41FBC29B600DB85C6 /* BSPanoramaView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BSPanoramaView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 9B9E00B71FBC29B600DB85C6 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 9B9E00B81FBC29B600DB85C6 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 9B9E00BA1FBC29B600DB85C6 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 9B9E00BB1FBC29B600DB85C6 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 9B9E00BE1FBC29B600DB85C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 9B9E00C01FBC29B600DB85C6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 9B9E00C31FBC29B600DB85C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 9B9E00C51FBC29B600DB85C6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 9B9E00C61FBC29B600DB85C6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 33 | 9B9E00CD1FBC29E300DB85C6 /* BSPanoramaView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BSPanoramaView.h; sourceTree = ""; }; 34 | 9B9E00CE1FBC29E300DB85C6 /* BSPanoramaView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BSPanoramaView.m; sourceTree = ""; }; 35 | 9B9E00D01FBC32C300DB85C6 /* SinglePanoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SinglePanoViewController.h; sourceTree = ""; }; 36 | 9B9E00D11FBC32C300DB85C6 /* SinglePanoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SinglePanoViewController.m; sourceTree = ""; }; 37 | 9B9E00D31FBC36F900DB85C6 /* TablePanoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TablePanoViewController.h; sourceTree = ""; }; 38 | 9B9E00D41FBC36F900DB85C6 /* TablePanoViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TablePanoViewController.m; sourceTree = ""; }; 39 | 9B9E00D61FBC380500DB85C6 /* PanoTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PanoTableViewCell.m; sourceTree = ""; }; 40 | 9B9E00D71FBC380500DB85C6 /* PanoTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PanoTableViewCell.h; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 9B9E00B11FBC29B600DB85C6 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | 9B9E00AB1FBC29B600DB85C6 = { 55 | isa = PBXGroup; 56 | children = ( 57 | 9B9E00B61FBC29B600DB85C6 /* BSPanoramaView */, 58 | 9B9E00B51FBC29B600DB85C6 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | 9B9E00B51FBC29B600DB85C6 /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 9B9E00B41FBC29B600DB85C6 /* BSPanoramaView.app */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | 9B9E00B61FBC29B600DB85C6 /* BSPanoramaView */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 9B9E00B71FBC29B600DB85C6 /* AppDelegate.h */, 74 | 9B9E00B81FBC29B600DB85C6 /* AppDelegate.m */, 75 | 9B9E00BA1FBC29B600DB85C6 /* ViewController.h */, 76 | 9B9E00BB1FBC29B600DB85C6 /* ViewController.m */, 77 | 9B9E00D01FBC32C300DB85C6 /* SinglePanoViewController.h */, 78 | 9B9E00D11FBC32C300DB85C6 /* SinglePanoViewController.m */, 79 | 9B9E00D31FBC36F900DB85C6 /* TablePanoViewController.h */, 80 | 9B9E00D41FBC36F900DB85C6 /* TablePanoViewController.m */, 81 | 9B9E00D71FBC380500DB85C6 /* PanoTableViewCell.h */, 82 | 9B9E00D61FBC380500DB85C6 /* PanoTableViewCell.m */, 83 | 9B9E00CD1FBC29E300DB85C6 /* BSPanoramaView.h */, 84 | 9B9E00CE1FBC29E300DB85C6 /* BSPanoramaView.m */, 85 | 9B9E00BD1FBC29B600DB85C6 /* Main.storyboard */, 86 | 9B9E00C01FBC29B600DB85C6 /* Assets.xcassets */, 87 | 9B9E00C21FBC29B600DB85C6 /* LaunchScreen.storyboard */, 88 | 9B9E00C51FBC29B600DB85C6 /* Info.plist */, 89 | 9B9E00C61FBC29B600DB85C6 /* main.m */, 90 | ); 91 | path = BSPanoramaView; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | 9B9E00B31FBC29B600DB85C6 /* BSPanoramaView */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = 9B9E00CA1FBC29B600DB85C6 /* Build configuration list for PBXNativeTarget "BSPanoramaView" */; 100 | buildPhases = ( 101 | 9B9E00B01FBC29B600DB85C6 /* Sources */, 102 | 9B9E00B11FBC29B600DB85C6 /* Frameworks */, 103 | 9B9E00B21FBC29B600DB85C6 /* Resources */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = BSPanoramaView; 110 | productName = BSPanoramaView; 111 | productReference = 9B9E00B41FBC29B600DB85C6 /* BSPanoramaView.app */; 112 | productType = "com.apple.product-type.application"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | 9B9E00AC1FBC29B600DB85C6 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastUpgradeCheck = 0910; 121 | ORGANIZATIONNAME = bestswifter; 122 | TargetAttributes = { 123 | 9B9E00B31FBC29B600DB85C6 = { 124 | CreatedOnToolsVersion = 9.1; 125 | ProvisioningStyle = Automatic; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = 9B9E00AF1FBC29B600DB85C6 /* Build configuration list for PBXProject "BSPanoramaView" */; 130 | compatibilityVersion = "Xcode 8.0"; 131 | developmentRegion = en; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = 9B9E00AB1FBC29B600DB85C6; 138 | productRefGroup = 9B9E00B51FBC29B600DB85C6 /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | 9B9E00B31FBC29B600DB85C6 /* BSPanoramaView */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | 9B9E00B21FBC29B600DB85C6 /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 9B9E00C41FBC29B600DB85C6 /* LaunchScreen.storyboard in Resources */, 153 | 9B9E00C11FBC29B600DB85C6 /* Assets.xcassets in Resources */, 154 | 9B9E00BF1FBC29B600DB85C6 /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | 9B9E00B01FBC29B600DB85C6 /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 9B9E00D21FBC32C300DB85C6 /* SinglePanoViewController.m in Sources */, 166 | 9B9E00BC1FBC29B600DB85C6 /* ViewController.m in Sources */, 167 | 9B9E00D81FBC380600DB85C6 /* PanoTableViewCell.m in Sources */, 168 | 9B9E00C71FBC29B600DB85C6 /* main.m in Sources */, 169 | 9B9E00D51FBC36F900DB85C6 /* TablePanoViewController.m in Sources */, 170 | 9B9E00CF1FBC29E300DB85C6 /* BSPanoramaView.m in Sources */, 171 | 9B9E00B91FBC29B600DB85C6 /* AppDelegate.m in Sources */, 172 | ); 173 | runOnlyForDeploymentPostprocessing = 0; 174 | }; 175 | /* End PBXSourcesBuildPhase section */ 176 | 177 | /* Begin PBXVariantGroup section */ 178 | 9B9E00BD1FBC29B600DB85C6 /* Main.storyboard */ = { 179 | isa = PBXVariantGroup; 180 | children = ( 181 | 9B9E00BE1FBC29B600DB85C6 /* Base */, 182 | ); 183 | name = Main.storyboard; 184 | sourceTree = ""; 185 | }; 186 | 9B9E00C21FBC29B600DB85C6 /* LaunchScreen.storyboard */ = { 187 | isa = PBXVariantGroup; 188 | children = ( 189 | 9B9E00C31FBC29B600DB85C6 /* Base */, 190 | ); 191 | name = LaunchScreen.storyboard; 192 | sourceTree = ""; 193 | }; 194 | /* End PBXVariantGroup section */ 195 | 196 | /* Begin XCBuildConfiguration section */ 197 | 9B9E00C81FBC29B600DB85C6 /* Debug */ = { 198 | isa = XCBuildConfiguration; 199 | buildSettings = { 200 | ALWAYS_SEARCH_USER_PATHS = NO; 201 | CLANG_ANALYZER_NONNULL = YES; 202 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 203 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 204 | CLANG_CXX_LIBRARY = "libc++"; 205 | CLANG_ENABLE_MODULES = YES; 206 | CLANG_ENABLE_OBJC_ARC = YES; 207 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 208 | CLANG_WARN_BOOL_CONVERSION = YES; 209 | CLANG_WARN_COMMA = YES; 210 | CLANG_WARN_CONSTANT_CONVERSION = YES; 211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 212 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 213 | CLANG_WARN_EMPTY_BODY = YES; 214 | CLANG_WARN_ENUM_CONVERSION = YES; 215 | CLANG_WARN_INFINITE_RECURSION = YES; 216 | CLANG_WARN_INT_CONVERSION = YES; 217 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 220 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 221 | CLANG_WARN_STRICT_PROTOTYPES = YES; 222 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 223 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 224 | CLANG_WARN_UNREACHABLE_CODE = YES; 225 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 226 | CODE_SIGN_IDENTITY = "iPhone Developer"; 227 | COPY_PHASE_STRIP = NO; 228 | DEBUG_INFORMATION_FORMAT = dwarf; 229 | ENABLE_STRICT_OBJC_MSGSEND = YES; 230 | ENABLE_TESTABILITY = YES; 231 | GCC_C_LANGUAGE_STANDARD = gnu11; 232 | GCC_DYNAMIC_NO_PIC = NO; 233 | GCC_NO_COMMON_BLOCKS = YES; 234 | GCC_OPTIMIZATION_LEVEL = 0; 235 | GCC_PREPROCESSOR_DEFINITIONS = ( 236 | "DEBUG=1", 237 | "$(inherited)", 238 | ); 239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 241 | GCC_WARN_UNDECLARED_SELECTOR = YES; 242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 243 | GCC_WARN_UNUSED_FUNCTION = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 246 | MTL_ENABLE_DEBUG_INFO = YES; 247 | ONLY_ACTIVE_ARCH = YES; 248 | SDKROOT = iphoneos; 249 | }; 250 | name = Debug; 251 | }; 252 | 9B9E00C91FBC29B600DB85C6 /* Release */ = { 253 | isa = XCBuildConfiguration; 254 | buildSettings = { 255 | ALWAYS_SEARCH_USER_PATHS = NO; 256 | CLANG_ANALYZER_NONNULL = YES; 257 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 259 | CLANG_CXX_LIBRARY = "libc++"; 260 | CLANG_ENABLE_MODULES = YES; 261 | CLANG_ENABLE_OBJC_ARC = YES; 262 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 263 | CLANG_WARN_BOOL_CONVERSION = YES; 264 | CLANG_WARN_COMMA = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 268 | CLANG_WARN_EMPTY_BODY = YES; 269 | CLANG_WARN_ENUM_CONVERSION = YES; 270 | CLANG_WARN_INFINITE_RECURSION = YES; 271 | CLANG_WARN_INT_CONVERSION = YES; 272 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 276 | CLANG_WARN_STRICT_PROTOTYPES = YES; 277 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 278 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | CODE_SIGN_IDENTITY = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 284 | ENABLE_NS_ASSERTIONS = NO; 285 | ENABLE_STRICT_OBJC_MSGSEND = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu11; 287 | GCC_NO_COMMON_BLOCKS = YES; 288 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 289 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 290 | GCC_WARN_UNDECLARED_SELECTOR = YES; 291 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 292 | GCC_WARN_UNUSED_FUNCTION = YES; 293 | GCC_WARN_UNUSED_VARIABLE = YES; 294 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 295 | MTL_ENABLE_DEBUG_INFO = NO; 296 | SDKROOT = iphoneos; 297 | VALIDATE_PRODUCT = YES; 298 | }; 299 | name = Release; 300 | }; 301 | 9B9E00CB1FBC29B600DB85C6 /* Debug */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 305 | CODE_SIGN_STYLE = Automatic; 306 | DEVELOPMENT_TEAM = DU8G6Z9DUA; 307 | INFOPLIST_FILE = BSPanoramaView/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 309 | PRODUCT_BUNDLE_IDENTIFIER = com.bestswifter.BSPanoramaView.BSPanoramaView; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | TARGETED_DEVICE_FAMILY = "1,2"; 312 | }; 313 | name = Debug; 314 | }; 315 | 9B9E00CC1FBC29B600DB85C6 /* Release */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 319 | CODE_SIGN_STYLE = Automatic; 320 | DEVELOPMENT_TEAM = DU8G6Z9DUA; 321 | INFOPLIST_FILE = BSPanoramaView/Info.plist; 322 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 323 | PRODUCT_BUNDLE_IDENTIFIER = com.bestswifter.BSPanoramaView.BSPanoramaView; 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | TARGETED_DEVICE_FAMILY = "1,2"; 326 | }; 327 | name = Release; 328 | }; 329 | /* End XCBuildConfiguration section */ 330 | 331 | /* Begin XCConfigurationList section */ 332 | 9B9E00AF1FBC29B600DB85C6 /* Build configuration list for PBXProject "BSPanoramaView" */ = { 333 | isa = XCConfigurationList; 334 | buildConfigurations = ( 335 | 9B9E00C81FBC29B600DB85C6 /* Debug */, 336 | 9B9E00C91FBC29B600DB85C6 /* Release */, 337 | ); 338 | defaultConfigurationIsVisible = 0; 339 | defaultConfigurationName = Release; 340 | }; 341 | 9B9E00CA1FBC29B600DB85C6 /* Build configuration list for PBXNativeTarget "BSPanoramaView" */ = { 342 | isa = XCConfigurationList; 343 | buildConfigurations = ( 344 | 9B9E00CB1FBC29B600DB85C6 /* Debug */, 345 | 9B9E00CC1FBC29B600DB85C6 /* Release */, 346 | ); 347 | defaultConfigurationIsVisible = 0; 348 | defaultConfigurationName = Release; 349 | }; 350 | /* End XCConfigurationList section */ 351 | }; 352 | rootObject = 9B9E00AC1FBC29B600DB85C6 /* Project object */; 353 | } 354 | -------------------------------------------------------------------------------- /BSPanoramaView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BSPanoramaView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /BSPanoramaView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | // Override point for customization after application launch. 21 | ViewController *viewController = [[ViewController alloc] init]; 22 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController]; 23 | self.window.rootViewController = nav; 24 | return YES; 25 | } 26 | 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application { 29 | // 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. 30 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 31 | } 32 | 33 | 34 | - (void)applicationDidEnterBackground:(UIApplication *)application { 35 | // 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. 36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 37 | } 38 | 39 | 40 | - (void)applicationWillEnterForeground:(UIApplication *)application { 41 | // 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. 42 | } 43 | 44 | 45 | - (void)applicationDidBecomeActive:(UIApplication *)application { 46 | // 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. 47 | } 48 | 49 | 50 | - (void)applicationWillTerminate:(UIApplication *)application { 51 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 52 | } 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /BSPanoramaView/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 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /BSPanoramaView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /BSPanoramaView/Assets.xcassets/placeholder.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "WechatIMG130.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /BSPanoramaView/Assets.xcassets/placeholder.imageset/WechatIMG130.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestswifter/BSPanoramaView/cc41ef1efe458f3d55ae97db63fb9434aa19245d/BSPanoramaView/Assets.xcassets/placeholder.imageset/WechatIMG130.png -------------------------------------------------------------------------------- /BSPanoramaView/Assets.xcassets/test.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "test-2.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /BSPanoramaView/Assets.xcassets/test.imageset/test-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestswifter/BSPanoramaView/cc41ef1efe458f3d55ae97db63fb9434aa19245d/BSPanoramaView/Assets.xcassets/test.imageset/test-2.png -------------------------------------------------------------------------------- /BSPanoramaView/BSPanoramaView.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSPanoramaView.h 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | @class BSPanoramaView; 14 | 15 | @interface PanoramaManager: NSObject 16 | 17 | @property (nonatomic, assign) GLKQuaternion lastQuaternion; ///< 存储最近一次有效的四元数 18 | 19 | + (PanoramaManager *)sharedInstance; 20 | - (void)registerView:(BSPanoramaView *)view; 21 | - (void)unRegisterView:(BSPanoramaView *)view; 22 | 23 | @end 24 | 25 | @interface BSPanoramaView : GLKView 26 | 27 | /** 28 | 新建全景图对象 29 | 30 | @param frame 图片大小 31 | @return 图片资源名称 32 | */ 33 | - (instancetype)initWithFrame:(CGRect)frame; 34 | 35 | /** 36 | 新建全景图对象 37 | 38 | @param frame 图片大小 39 | @param imageName 图片资源名称,如果图片分辨率高于 4096 * 2048,为了避免过高的内存占用会拒绝加载 40 | @return 全景图对象 41 | */ 42 | - (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageName; 43 | 44 | /** 45 | 加载全景图片 46 | 47 | @param imageName 全景图图片名称 48 | */ 49 | - (void)setImageWithName:(NSString *)imageName; 50 | 51 | /** 52 | 当不再使用时应该释放内存,并且把自己从全局的 PanoramaManager 中移除 53 | */ 54 | - (void)unloadImage; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /BSPanoramaView/BSPanoramaView.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSPanoramaView.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import "BSPanoramaView.h" 10 | 11 | @interface BSPanoramaView () 12 | 13 | #pragma -mark OpenGL 相关属性 14 | @property (nonatomic, assign) BOOL shouldUnload; /// 是否需要释放纹理的标记位 15 | @property (nonatomic, assign) int numIndices; /// 索引数 16 | @property (nonatomic, assign) GLuint vertexIndicesBufferID; /// 顶点索引缓存指针 17 | @property (nonatomic, assign) GLuint vertexBufferID; /// 顶点缓存指针 18 | @property (nonatomic, assign) GLuint vertexTexCoordID; /// 纹理缓存指针 19 | @property (nonatomic, strong) GLKBaseEffect *effect; /// 着色器 20 | 21 | #pragma -mark 手势相关属性 22 | @property (nonatomic, strong) UIPanGestureRecognizer *pan; /// 滑动手势 23 | @property (nonatomic, assign) CGFloat panX; /// 水平位移 24 | @property (nonatomic, assign) CGFloat panY; /// 垂直位移 25 | @property (nonatomic, strong) UIPinchGestureRecognizer *pinch; /// 缩放手势 26 | @property (nonatomic, assign) CGFloat scale; /// 缩放比例 27 | 28 | @end 29 | 30 | @implementation BSPanoramaView 31 | 32 | - (instancetype)initWithFrame:(CGRect)frame { 33 | self = [super initWithFrame:frame]; 34 | if (self) { 35 | self.enableSetNeedsDisplay = NO; 36 | [self setupOpenGL]; /// OpenGL 初始化设置 37 | [self addGestureRecognizer]; /// 添加手势 38 | } 39 | return self; 40 | } 41 | 42 | - (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageName { 43 | self = [self initWithFrame:frame]; 44 | if (self) { 45 | [self setImageWithName:imageName]; 46 | } 47 | return self; 48 | } 49 | 50 | - (void)dealloc { 51 | [self unloadImage]; 52 | } 53 | 54 | - (void)setImageWithName:(NSString *)imageName { 55 | self.shouldUnload = NO; 56 | /// 将图片转换成为纹理信息,由于OpenGL的默认坐标系设置在左下角, 而GLKit在左上角, 因此需要转换 57 | NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], GLKTextureLoaderOriginBottomLeft, nil]; 58 | UIImage *textureImage = [UIImage imageNamed:imageName]; 59 | if (textureImage.size.height * textureImage.size.width > 4096.1f * 2048.1f) { 60 | return ; 61 | } 62 | GLKTextureLoader *loader = [[GLKTextureLoader alloc] initWithSharegroup:self.context.sharegroup]; 63 | [loader textureWithCGImage:textureImage.CGImage options:options queue:dispatch_get_main_queue() completionHandler:^(GLKTextureInfo * _Nullable textureInfo, NSError * _Nullable outError) { 64 | [[PanoramaManager sharedInstance] registerView:self]; 65 | if (self.shouldUnload) { // 因为是异步加载,所以需要考虑调用完 unloadImage 才加载成功的情况 66 | [[PanoramaManager sharedInstance] unRegisterView:self]; 67 | GLuint name = textureInfo.name; 68 | glDeleteTextures(1, &name); 69 | glDrawElements(GL_TRIANGLES, self.numIndices, GL_UNSIGNED_SHORT, 0); 70 | return ; 71 | } 72 | 73 | /// 设置着色器的纹理 74 | self.effect = [[GLKBaseEffect alloc] init]; 75 | self.effect.texture2d0.enabled = GL_TRUE; 76 | self.effect.texture2d0.name = textureInfo.name; 77 | }]; 78 | } 79 | 80 | - (void)unloadImage { 81 | self.shouldUnload = YES; 82 | [[PanoramaManager sharedInstance] unRegisterView:self]; 83 | 84 | GLuint name = self.effect.texture2d0.name; 85 | glDeleteTextures(1, &name); 86 | glDrawElements(GL_TRIANGLES, self.numIndices, GL_UNSIGNED_SHORT, 0); 87 | } 88 | 89 | - (void)setupOpenGL { 90 | self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 91 | [EAGLContext setCurrentContext:self.context]; 92 | 93 | /// 设置buffer 94 | GLfloat *vVertices = NULL; /// 顶点 95 | GLfloat *vTextCoord = NULL; /// 纹理 96 | GLushort *indices = NULL; /// 索引 97 | 98 | int numVertices = 0; 99 | self.numIndices = esGenSphere(100, 1.0, &vVertices, &vTextCoord, &indices, &numVertices); 100 | 101 | /// 索引 102 | glGenBuffers(1, &_vertexIndicesBufferID); 103 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vertexIndicesBufferID); 104 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, self.numIndices*sizeof(GLushort), indices, GL_STATIC_DRAW); 105 | 106 | /// 顶点数据 107 | glGenBuffers(1, &_vertexBufferID); 108 | glBindBuffer(GL_ARRAY_BUFFER, self.vertexBufferID); 109 | glBufferData(GL_ARRAY_BUFFER, numVertices*3*sizeof(GLfloat), vVertices, GL_STATIC_DRAW); 110 | glEnableVertexAttribArray(GLKVertexAttribPosition); /// 顶点位置属性 111 | glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*3, NULL); 112 | 113 | /// 纹理数据 114 | glGenBuffers(1, &_vertexTexCoordID); 115 | glBindBuffer(GL_ARRAY_BUFFER, self.vertexTexCoordID); 116 | glBufferData(GL_ARRAY_BUFFER, numVertices*2*sizeof(GLfloat), vTextCoord, GL_STATIC_DRAW); 117 | glEnableVertexAttribArray(GLKVertexAttribTexCoord0); /// 纹理位置属性 118 | glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, NULL); 119 | } 120 | 121 | #pragma mark --- 生成球的几何结构---- 122 | // 参考:https://github.com/danginsburg/opengles-book-samples/blob/604a02cc84f9cc4369f7efe93d2a1d7f2cab2ba7/iPhone/Common/esUtil.h#L110 123 | int esGenSphere(int numSlices, float radius, float **vertices, 124 | float **texCoords, uint16_t **indices, int *numVertices_out) { 125 | int numParallels = numSlices / 2; 126 | int numVertices = (numParallels + 1) * (numSlices + 1); 127 | int numIndices = numParallels * numSlices * 6; 128 | float angleStep = (2.0f * 3.14159265358f) / ((float) numSlices); 129 | 130 | if (vertices != NULL) { 131 | *vertices = malloc(sizeof(float) * 3 * numVertices); 132 | } 133 | 134 | if (texCoords != NULL) { 135 | *texCoords = malloc(sizeof(float) * 2 * numVertices); 136 | } 137 | 138 | if (indices != NULL) { 139 | *indices = malloc(sizeof(uint16_t) * numIndices); 140 | } 141 | 142 | for (int i = 0; i < numParallels + 1; i++) { 143 | for (int j = 0; j < numSlices + 1; j++) { 144 | int vertex = (i * (numSlices + 1) + j) * 3; 145 | 146 | if (vertices) { 147 | (*vertices)[vertex + 0] = radius * sinf(angleStep * (float)i) * sinf(angleStep * (float)j); 148 | (*vertices)[vertex + 1] = radius * cosf(angleStep * (float)i); 149 | (*vertices)[vertex + 2] = radius * sinf(angleStep * (float)i) * cosf(angleStep * (float)j); 150 | } 151 | 152 | if (texCoords) { 153 | int texIndex = (i * (numSlices + 1) + j) * 2; 154 | (*texCoords)[texIndex + 0] = (float)j / (float)numSlices; 155 | (*texCoords)[texIndex + 1] = 1.0f - ((float)i / (float)numParallels); 156 | } 157 | } 158 | } 159 | 160 | // Generate the indices 161 | if (indices != NULL) { 162 | uint16_t *indexBuf = (*indices); 163 | for (int i = 0; i < numParallels ; i++) { 164 | for (int j = 0; j < numSlices; j++) { 165 | *indexBuf++ = i * (numSlices + 1) + j; 166 | *indexBuf++ = (i + 1) * (numSlices + 1) + j; 167 | *indexBuf++ = (i + 1) * (numSlices + 1) + (j + 1); 168 | 169 | *indexBuf++ = i * (numSlices + 1) + j; 170 | *indexBuf++ = (i + 1) * (numSlices + 1) + (j + 1); 171 | *indexBuf++ = i * (numSlices + 1) + (j + 1); 172 | } 173 | } 174 | } 175 | 176 | if (numVertices_out) { 177 | *numVertices_out = numVertices; 178 | } 179 | 180 | return numIndices; 181 | } 182 | 183 | #pragma mark 手势添加与识别 184 | - (void)addGestureRecognizer{ 185 | /// 平移手势 186 | self.pan =[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; 187 | [self addGestureRecognizer:self.pan]; 188 | 189 | /// 捏合手势 190 | self.pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)]; 191 | [self addGestureRecognizer:self.pinch]; 192 | self.scale = 1.428571f; 193 | } 194 | 195 | - (void)panAction:(UIPanGestureRecognizer *)pan { 196 | CGPoint point = [pan translationInView:self]; 197 | self.panX += point.x; 198 | self.panY += point.y; 199 | 200 | [pan setTranslation:CGPointZero inView:self]; //每次变换之后, 把改变值归零 201 | } 202 | 203 | - (void)pinchAction:(UIPinchGestureRecognizer *)pinch { 204 | self.scale *= pinch.scale; 205 | pinch.scale = 1.0; 206 | } 207 | 208 | #pragma mark 绘制 209 | - (void)drawRect:(CGRect)rect { 210 | [self update]; 211 | [self.effect prepareToDraw]; 212 | 213 | glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 214 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 215 | glDrawElements(GL_TRIANGLES, self.numIndices, GL_UNSIGNED_SHORT, 0); 216 | } 217 | 218 | - (void)update{ 219 | CGSize size = self.bounds.size; 220 | float aspect = fabs(size.width / size.height); 221 | 222 | /** 223 | * 根据缩放比例, 设置焦距 224 | */ 225 | CGFloat ovyRadians = 100 / self.scale; 226 | 227 | // ovyRadians 不小于 50, 不大于 120; 228 | if (ovyRadians < 50) { 229 | ovyRadians = 50; 230 | self.scale = 1 / (50.0 / 100); 231 | } 232 | if (ovyRadians > 120) { 233 | ovyRadians = 120; 234 | self.scale = 1 / (120.0 / 100); 235 | } 236 | 237 | /**GLKMatrix4MakePerspective 配置透视图 238 | 第一个参数, 类似于相机的焦距, 比如10表示窄角度, 100表示广角 一般65-75; 239 | 第二个参数: 表示时屏幕的纵横比 240 | 第三个, 第四参数: 是为了实现透视效果, 近大远处小, 要确保模型位于远近平面之间 241 | */ 242 | 243 | GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(ovyRadians), aspect, 0.1f, 400.0f); 244 | projectionMatrix = GLKMatrix4Scale(projectionMatrix, -1.0f, 1.0f, 1.0f); 245 | 246 | GLKMatrix4 rotation = GLKMatrix4MakeWithQuaternion([PanoramaManager sharedInstance].lastQuaternion); 247 | 248 | projectionMatrix = GLKMatrix4RotateX(projectionMatrix, -0.005*self.panY); 249 | projectionMatrix = GLKMatrix4Multiply(projectionMatrix, rotation); 250 | 251 | /// 为了保证在水平放置手机的时候, 是从下往上看, 因此首先坐标系沿着x轴旋转90度 252 | projectionMatrix = GLKMatrix4RotateX(projectionMatrix, M_PI_2); 253 | self.effect.transform.projectionMatrix = projectionMatrix; 254 | 255 | GLKMatrix4 modelViewMatrix = GLKMatrix4Identity; 256 | modelViewMatrix = GLKMatrix4RotateY(modelViewMatrix, 0.005*self.panX); 257 | self.effect.transform.modelviewMatrix = modelViewMatrix; 258 | } 259 | 260 | @end 261 | 262 | @interface PanoramaManager() 263 | 264 | @property (nonatomic, strong) NSHashTable *panoViews; 265 | @property (nonatomic, strong) CMMotionManager *motionManager; 266 | 267 | @end 268 | 269 | @implementation PanoramaManager 270 | 271 | + (PanoramaManager *)sharedInstance { 272 | static PanoramaManager *panoramaManager = nil; 273 | static dispatch_once_t onceToken; 274 | dispatch_once(&onceToken, ^{ 275 | panoramaManager = [[PanoramaManager alloc] init]; 276 | }); 277 | return panoramaManager; 278 | } 279 | 280 | - (instancetype)init { 281 | self = [super init]; 282 | if (self) { 283 | _motionManager = [[CMMotionManager alloc] init]; 284 | _motionManager.deviceMotionUpdateInterval = 1.0 / 60.0; //设置运动更新间隔 285 | _motionManager.showsDeviceMovementDisplay = YES; // 是否展示运动 286 | [_motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical]; 287 | 288 | _panoViews = [[NSHashTable alloc] initWithOptions:NSHashTableWeakMemory capacity:2]; 289 | 290 | CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(display:)]; 291 | [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 292 | } 293 | return self; 294 | } 295 | 296 | - (void)registerView:(BSPanoramaView *)view { 297 | [self.panoViews addObject:view]; 298 | } 299 | 300 | - (void)unRegisterView:(BSPanoramaView *)view { 301 | if ([self.panoViews containsObject:view]) { 302 | [self.panoViews removeObject:view]; 303 | } 304 | } 305 | 306 | - (void)display:(CADisplayLink *)displayLink { 307 | if (self.motionManager) { // 从后台回到前台时,CoreMotion 可能还没有工作,这里会拿到空的四元数,导致渲染失败 308 | CMDeviceMotion *deviceMotion = self.motionManager.deviceMotion; 309 | 310 | double w = deviceMotion.attitude.quaternion.w; 311 | double wx = deviceMotion.attitude.quaternion.x; 312 | double wy = deviceMotion.attitude.quaternion.y; 313 | double wz = deviceMotion.attitude.quaternion.z; 314 | self.lastQuaternion = GLKQuaternionMake(-wx, wy, wz, w); 315 | } 316 | 317 | #if TARGET_OS_SIMULATOR 318 | self.lastQuaternion = GLKQuaternionMake(0, 0, 1, 1); // 为模拟器提供假的传感器数据 319 | #endif 320 | 321 | for (BSPanoramaView *view in self.panoViews) { 322 | if (view) { 323 | [view display]; 324 | } 325 | } 326 | } 327 | 328 | @end 329 | -------------------------------------------------------------------------------- /BSPanoramaView/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /BSPanoramaView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /BSPanoramaView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /BSPanoramaView/PanoTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // PanoTableViewCell.h 3 | // 全景_图片 4 | // 5 | // Created by 张星宇 on 11/14/17. 6 | // Copyright © 2017 H. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface PanoTableViewCell : UITableViewCell 12 | 13 | - (void)willBeDisplayed:(NSUInteger)index; 14 | - (void)didStopDisplayed:(NSUInteger)index; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /BSPanoramaView/PanoTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // PanoTableViewCell.m 3 | // 全景_图片 4 | // 5 | // Created by 张星宇 on 11/14/17. 6 | // Copyright © 2017 H. All rights reserved. 7 | // 8 | 9 | #import "PanoTableViewCell.h" 10 | #import "BSPanoramaView.h" 11 | 12 | #define kPanoViewInterval 4 13 | 14 | @interface PanoTableViewCell() 15 | 16 | @property (nonatomic, strong) BSPanoramaView *panoView; 17 | 18 | @end 19 | 20 | @implementation PanoTableViewCell 21 | 22 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 23 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 24 | if (self) { 25 | CGRect rect = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 300); 26 | self.panoView = [[BSPanoramaView alloc] initWithFrame:rect]; 27 | [self.contentView addSubview:self.panoView]; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 33 | [super setSelected:selected animated:animated]; 34 | } 35 | 36 | - (void)willBeDisplayed:(NSUInteger)index { 37 | [self.panoView setImageWithName:@"test"]; 38 | } 39 | 40 | - (void)didStopDisplayed:(NSUInteger)index { 41 | [self.panoView unloadImage]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /BSPanoramaView/SinglePanoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableviewTestViewController.h 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SinglePanoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BSPanoramaView/SinglePanoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableviewTestViewController.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import "SinglePanoViewController.h" 10 | #import "BSPanoramaView.h" 11 | 12 | @interface SinglePanoViewController () 13 | 14 | @end 15 | 16 | @implementation SinglePanoViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | self.view.backgroundColor = [UIColor whiteColor]; 21 | 22 | CGRect panoRect = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height- 64); 23 | BSPanoramaView *panoView = [[BSPanoramaView alloc] initWithFrame:panoRect imageName:@"test"]; 24 | [self.view addSubview:panoView]; 25 | } 26 | 27 | - (void)didReceiveMemoryWarning { 28 | [super didReceiveMemoryWarning]; 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | /* 33 | #pragma mark - Navigation 34 | 35 | // In a storyboard-based application, you will often want to do a little preparation before navigation 36 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 37 | // Get the new view controller using [segue destinationViewController]. 38 | // Pass the selected object to the new view controller. 39 | } 40 | */ 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /BSPanoramaView/TablePanoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TablePanoViewController.h 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TablePanoViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BSPanoramaView/TablePanoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TablePanoViewController.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import "TablePanoViewController.h" 10 | #import "PanoTableViewCell.h" 11 | 12 | @interface TablePanoViewController () 13 | 14 | @end 15 | 16 | @implementation TablePanoViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 414, 736)]; 22 | tableView.delegate = self; 23 | tableView.dataSource = self; 24 | 25 | tableView.estimatedRowHeight = 736; 26 | [self.view addSubview:tableView]; 27 | } 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | // Dispose of any resources that can be recreated. 32 | } 33 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 34 | return 60; 35 | } 36 | 37 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 38 | if (indexPath.row % 4 == 3) { 39 | PanoTableViewCell *cell = (PanoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PanoTableViewCell"]; 40 | if (!cell) { 41 | cell = [[PanoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PanoTableViewCell"]; 42 | } 43 | return cell; 44 | } 45 | else { 46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; 47 | if (!cell) { 48 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"]; 49 | cell.textLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row]; 50 | cell.contentView.backgroundColor = [UIColor grayColor]; 51 | } 52 | return cell; 53 | } 54 | } 55 | 56 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 57 | return 300; 58 | } 59 | 60 | - (void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 61 | if ([cell isKindOfClass:[PanoTableViewCell class]]) { 62 | PanoTableViewCell *panoCell = (PanoTableViewCell *)cell; 63 | [panoCell willBeDisplayed:indexPath.row]; 64 | } 65 | } 66 | 67 | - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 68 | if ([cell isKindOfClass:[PanoTableViewCell class]]) { 69 | PanoTableViewCell *panoCell = (PanoTableViewCell *)cell; 70 | [panoCell didStopDisplayed:indexPath.row]; 71 | } 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /BSPanoramaView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /BSPanoramaView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "TablePanoViewController.h" 12 | #import "SinglePanoViewController.h" 13 | 14 | @interface ViewController () 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | self.view.backgroundColor = [UIColor whiteColor]; 23 | 24 | UIButton *jumpToSingleButton = [UIButton buttonWithType:UIButtonTypeCustom]; 25 | jumpToSingleButton.frame = CGRectMake(50, 200 + 10, [UIScreen mainScreen].bounds.size.width - 100, 40); 26 | [jumpToSingleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 27 | [jumpToSingleButton setBackgroundColor:[UIColor grayColor]]; 28 | [jumpToSingleButton setTitle:@"测试单个全景图" forState:UIControlStateNormal]; 29 | [jumpToSingleButton addTarget:self action:@selector(navigateToSinglePanoView:) forControlEvents:UIControlEventTouchUpInside]; 30 | [self.view addSubview:jumpToSingleButton]; 31 | 32 | UIButton *jumpToMultiButton = [UIButton buttonWithType:UIButtonTypeCustom]; 33 | jumpToMultiButton.frame = CGRectMake(50, 300 + 10, [UIScreen mainScreen].bounds.size.width - 100, 40); 34 | [jumpToMultiButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 35 | [jumpToMultiButton setBackgroundColor:[UIColor grayColor]]; 36 | [jumpToMultiButton setTitle:@"在 UITableview 中测试" forState:UIControlStateNormal]; 37 | [jumpToMultiButton addTarget:self action:@selector(navigateToMultiPanoView:) forControlEvents:UIControlEventTouchUpInside]; 38 | [self.view addSubview:jumpToMultiButton]; 39 | } 40 | 41 | - (void)navigateToSinglePanoView:(id)sender { 42 | [self.navigationController pushViewController:[SinglePanoViewController new] animated:YES]; 43 | } 44 | 45 | - (void)navigateToMultiPanoView:(id)sender { 46 | [self.navigationController pushViewController:[TablePanoViewController new] animated:YES]; 47 | } 48 | 49 | - (void)didReceiveMemoryWarning { 50 | [super didReceiveMemoryWarning]; 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /BSPanoramaView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BSPanoramaView 4 | // 5 | // Created by 张星宇 on 11/15/17. 6 | // Copyright © 2017 bestswifter. 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 | -------------------------------------------------------------------------------- /Chinese.md: -------------------------------------------------------------------------------- 1 | # BSPanoramaView 2 | 3 | BSPanoramaView 是 iOS 平台上一个轻量的全景图组件,**它不依赖任何第三方框架,仅有 300 多行代码,最终的包大小只会增加 30Kb 左右。** 4 | 5 | ![](./BSPanorama.gif) 6 | 7 | 由于录制屏幕的原因,横屏效果无法展示,在真机上会有更好的用户体验。 8 | 9 | BSPanoramaView 从 [WushuputiGH/Panorama](https://github.com/WushuputiGH/Panorama) 这个 Repo 中借鉴了很多 OpenGL 相关的运算,主要涉及模型生成以及矩阵变换。 10 | 11 | BSPanoramaView 重构了整个应用层并且修复了几个重大的 bug,因此基本上可以投入生产环境使用。可能是因为没有正式测试的原因,目前没有发现明显的问题。如果你的项目对性能和稳定性的要求不是变态级别的,可以考虑使用 BSPanoramaView 或者在此基础上略作修改。 12 | 13 | # 使用方法 14 | 15 | `BSPanoramaView` 是 `GLKView` 的子类,而后者又是 `UIView` 的子类,所以可以直接把 `BSPanoramaView` 当成一个普通的 `UIView` 来使用,比如: 16 | 17 | ```objc 18 | #import "BSPanoramaView.h" 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | BSPanoramaView *panoView = [[BSPanoramaView alloc] initWithFrame:self.view.bounds imageName:@"test"]; 24 | [self.view addSubview:panoView]; 25 | } 26 | ``` 27 | 28 | OpenGL 的纹理,也就是图片,相当占用内存。以一张 4096 * 2048 的图片为例,它会占用 `4096 * 2048 * 4 / 1024 / 1024 = 32M` 的内存,这个虽然难以避免但我们应该对此保持警惕,尽可能及时的释放它。当 `BSPanoramaView` 的实例被释放时,它的 `dealloc` 函数会调用 `unloadImage` 方法释放内存: 29 | 30 | ```objc 31 | - (void)dealloc { 32 | [self unloadImage]; 33 | } 34 | ``` 35 | 36 | 在这种情况下,内存管理对使用者是透明的,无需额外的关注。但如果在 `UITableview` 中使用了 BSPanoramaView,由于 cell 会被重用,因此在 cell 滑出屏幕外时,需要手动调用 `unloadImage` 方法,这在 Demo 的 `PanoTableViewCell` 类中有具体的代码。 37 | 38 | # 安装方法 39 | 40 | 由于整个项目只有两个文件,所以直接拖到工程里也是可以的。然而 BSPanoramaView 还处于不稳定的版本,随时会有更新来修复 bug 或者新增功能,所以我的建议是使用 Cocoapods: 41 | 42 | ``` 43 | pod 'BSPanoramaView' 44 | ``` 45 | 46 | # 原理介绍 47 | 48 | 就像把大象放进箱子里需要三步一样,全景图控件并非系统提供,也需要以下几个步骤: 49 | 50 | 1. 生成一个球,这个球是由多个三角形近似拼接起来的,三角形的顶点就是 OpenGL 中的顶点数组对象(VBO) 51 | 2. 想象一下两个三角形可以拼成一个矩形,用三角形表示的话需要六个点,但实际上矩形只要四个点,这是因为有两个点被重复了,导致浪费了一些内存空间,这时候我们定义一个四个顶点的数组,然后用数组下标来表示顶点,再多的顶点也不会增加多少内存占用,这叫索引缓冲对象(IBO) 52 | 3. 有了顶点数组对象和索引缓冲对象以后,OpenGL 就可以画出一个球了,接来下的任务就是加载纹理,也就是图片,并且把纹理贴到球上。 53 | 54 | 以上基本上就是 OpenGL 的绘制过程,对 OpenGL 完全不了解的同学可以参考[这篇文章](https://learnopengl-cn.github.io/01%20Getting%20started/04%20Hello%20Triangle/) 简单的学习一下。在 `BSPanoramaView` 中,由于不考虑多平台兼容,所以使用了 OC 的 GLKit,它是对 OpenGL 的封装,提供了很多有效的函数。 55 | 56 | `BSPanoramaView` 中的 `setupOpenGL` 方法就是处理这个问题的。 57 | 58 | ## 定时绘制 59 | 60 | OpenGL 需要我们手动管理绘制,也就是一秒钟绘制 60 帧,这可以通过 `CADisplayLink` 实现。 61 | 62 | 不管是设备的晃动还是手势拖拽,最终都会以变换矩阵的形式呈现,应用到 OpenGL 中并且改变我们看到的结果。 63 | 64 | 考虑到多个 `BSPanoramaView` 实例有可能同时存在,为了避免性能损耗,我使用了单例的 `PanoramaManager` 负责获取设备的位移信息,并且注册了 `CADisplayLink` 负责定时绘制。 65 | 66 | 每个 `BSPanoramaView` 都会把自己注册到 manager 的弱引用数组中,这样可以确保自己的绘制方法每 1/60 秒都会被调用一次。同样的,`BSPanoramaView` 也不会访问设备的位置信息,而是由单例的 manager 获取一次,然后分发给多个实例。 67 | 68 | ## 传感器信息 69 | 70 | 传统的描述位置信息的方法是欧拉角,它由三个角度(横滚、偏航、俯仰)组成,然而欧拉角的最大问题是万向节死锁,导致角度错乱。因此在 iOS 上我们使用四元数避免上述问题,而且通过 GLKit 的 `GLKMatrix4MakeWithQuaternion` 函数直接转换成变换矩阵。 71 | 72 | 为了兼容模拟器,我构造了一个固定的四元数。 73 | 74 | ## 矩阵变换 75 | 76 | 无论是滑动手势还是缩放手势,最终都会转换成矩阵运算,从[WushuputiGH/Panorama](https://github.com/WushuputiGH/Panorama) 中抄来的代码虽然看起来格式不太正确,但工作起来却意外的毫无问题,暂时没有调整的计划。 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BSPanoramaView 2 | 3 | 中文文档请阅读[这里](./Chinese.md) 4 | 5 | ![](./BSPanorama.gif) 6 | 7 | Due to the limitation of recording screen, the actual experience on real device is much better the gif shown above. 8 | 9 | BSPanoramaView is a lightweight panorama picture browser on iOS platform, which will only make the binary file 30k larger. 10 | 11 | BSPanoramaView does not rely on any other third party framework and it only contains about three hundred lines of code. 12 | 13 | BSPanoramaView was inspired by [WushuputiGH/Panorama](https://github.com/WushuputiGH/Panorama) and copied some calculations about OpenGL but rewrote the application architecture and fixed many bugs. 14 | 15 | At current time, BSPanoramaView can be applied in production environment if you are tolerant of some tiny defects. 16 | 17 | # Usage 18 | 19 | BSPanoramaView is the subclass of `GLKView` which itself is a subclass of `UIView`, so you can use BSPanoramaView as a normal view: 20 | 21 | ```objc 22 | #import "BSPanoramaView.h" 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | 27 | BSPanoramaView *panoView = [[BSPanoramaView alloc] initWithFrame:self.view.bounds imageName:@"test"]; 28 | [self.view addSubview:panoView]; 29 | } 30 | ``` 31 | 32 | The texture(test.png) takes a lot of memory. For example, an picture with resolution of 4096 * 20148 takes 32M memory which means you should be careful about the memory occupation. 33 | 34 | When the instance of BSPanoramaView is released, it will unload the texture in `dealloc` method and you don't need to pay any extra attention to this: 35 | 36 | ```objc 37 | - (void)dealloc { 38 | [self unloadImage]; 39 | } 40 | ``` 41 | 42 | However, if it is not released, such as scrolling outside the screen, you should be careful to call `unloadImage` method manually at proper time. This is also demostrated in the code in `PanoTableViewCell` class. 43 | 44 | # Installation 45 | 46 | You can just copy the source code into your project because there are only two files. 47 | 48 | However, since this is a beta-version code which may be optimized constantly, I strongly encourage you to use **Cocoapods**: 49 | 50 | ``` 51 | pod 'BSPanoramaView' 52 | ``` 53 | --------------------------------------------------------------------------------