├── .gitignore ├── LICENSE ├── README.md ├── SGPopSelectView.podspec ├── SGPopSelectView ├── SGPopSelectViewDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── SGPopSelectViewDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── SGPopSelectViewTests │ ├── Info.plist │ └── SGPopSelectViewTests.m ├── classes ├── SGPopSelectView.h ├── SGPopSelectView.m └── sg_pop_images.xcassets │ ├── oval_selected.imageset │ ├── Contents.json │ └── Oval 3.png │ └── oval_unselected.imageset │ ├── Contents.json │ └── Oval 4.png └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sagi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SGPopSelectVIew 2 | =============== 3 | 4 | 一个简洁、美观的单选弹出视图 5 | 6 | ![demo](./demo.gif) 7 | 8 | ### 特点 9 | - 自适应选项内容调整自身大小,不用担心选项标题过长被截断显示。 10 | - 根据传入基准点自适应在父试图中显示的位置。 11 | 12 | ### 用法 13 | 初始化 14 | ```objective-c 15 | self.selections = @[@"Shake It Off",@"All About that Bass",@"Animals",@"Take Me To Church",@"Out Of The Woods",@"Centuries",@"I'm Not the Only One",@"Burnin' It Down"]; 16 | self.popView = [[SGPopSelectView alloc] init]; 17 | self.popView.selections = self.selections; 18 | __weak typeof(self) weakSelf = self; 19 | self.popView.selectedHandle = ^(NSInteger selectedIndex){ 20 | NSLog(@"selected index %ld, content is %@", selectedIndex, weakSelf.selections[selectedIndex]); 21 | }; 22 | ``` 23 | 24 | 显示 25 | 26 | ```objective-c 27 | CGPoint p = [(UIButton *)sender center]; 28 | [self.popView showFromView:self.view atPoint:p animated:YES]; 29 | ``` 30 | 隐藏 31 | ```objective-c 32 | [self.popView hide:YES]; 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /SGPopSelectView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SGPopSelectView" 3 | s.version = "0.3" 4 | s.summary = "A simple beautiful popup view for single selection." 5 | s.description = "A simple beautiful popup view for single selection, adjust size to fit it's content and also superview." 6 | s.homepage = "https://github.com/sagiwei/SGPopSelectView" 7 | s.license = { :type => "MIT", :file => "LICENSE" } 8 | s.author = { "sagiwei" => "sagiwei@gmail.com" } 9 | 10 | s.source = { :git => "https://github.com/sagiwei/SGPopSelectView.git", :tag => "v0.2" } 11 | s.source_files = "classes/*.{h,m}" 12 | s.resources = 'classes/sg_pop_images.xcassets' 13 | 14 | s.platform = :ios, '6.0' 15 | s.framework = 'UIKit' 16 | s.requires_arc = true 17 | end 18 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B64D7BC31A00EAB6004DC2BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B64D7BC21A00EAB6004DC2BA /* AppDelegate.m */; }; 11 | B64D7BC61A00EAB6004DC2BA /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B64D7BC51A00EAB6004DC2BA /* ViewController.m */; }; 12 | B64D7BCB1A00EAB6004DC2BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B64D7BCA1A00EAB6004DC2BA /* Images.xcassets */; }; 13 | B64D7BDA1A00EAB6004DC2BA /* SGPopSelectViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B64D7BD91A00EAB6004DC2BA /* SGPopSelectViewTests.m */; }; 14 | B6A737541A010E5400537311 /* sg_pop_images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B6A737511A010E5400537311 /* sg_pop_images.xcassets */; }; 15 | B6A737551A010E5400537311 /* SGPopSelectView.m in Sources */ = {isa = PBXBuildFile; fileRef = B6A737531A010E5400537311 /* SGPopSelectView.m */; }; 16 | B6A737581A010F1500537311 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B6A737561A010F1500537311 /* Main.storyboard */; }; 17 | B6A7375B1A010F2500537311 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = B6A737591A010F2500537311 /* LaunchScreen.xib */; }; 18 | B6A7375D1A010F3400537311 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B6A7375C1A010F3400537311 /* main.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | B64D7BD41A00EAB6004DC2BA /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = B64D7BB21A00EAB6004DC2BA /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = B64D7BB91A00EAB6004DC2BA; 27 | remoteInfo = SGPopSelectView; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | B64D7BBA1A00EAB6004DC2BA /* SGPopSelectViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SGPopSelectViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | B64D7BBE1A00EAB6004DC2BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | B64D7BC11A00EAB6004DC2BA /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | B64D7BC21A00EAB6004DC2BA /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | B64D7BC41A00EAB6004DC2BA /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | B64D7BC51A00EAB6004DC2BA /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | B64D7BCA1A00EAB6004DC2BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 39 | B64D7BD31A00EAB6004DC2BA /* SGPopSelectViewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SGPopSelectViewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | B64D7BD81A00EAB6004DC2BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | B64D7BD91A00EAB6004DC2BA /* SGPopSelectViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SGPopSelectViewTests.m; sourceTree = ""; }; 42 | B6A737511A010E5400537311 /* sg_pop_images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = sg_pop_images.xcassets; sourceTree = ""; }; 43 | B6A737521A010E5400537311 /* SGPopSelectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGPopSelectView.h; sourceTree = ""; }; 44 | B6A737531A010E5400537311 /* SGPopSelectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGPopSelectView.m; sourceTree = ""; }; 45 | B6A737571A010F1500537311 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | B6A7375A1A010F2500537311 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 47 | B6A7375C1A010F3400537311 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | B64D7BB71A00EAB6004DC2BA /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | B64D7BD01A00EAB6004DC2BA /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | B64D7BB11A00EAB6004DC2BA = { 69 | isa = PBXGroup; 70 | children = ( 71 | B64D7BBC1A00EAB6004DC2BA /* SGPopSelectView */, 72 | B64D7BE31A00EACB004DC2BA /* SGPopSelectViewDemo */, 73 | B64D7BD61A00EAB6004DC2BA /* SGPopSelectViewTests */, 74 | B64D7BBB1A00EAB6004DC2BA /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | B64D7BBB1A00EAB6004DC2BA /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | B64D7BBA1A00EAB6004DC2BA /* SGPopSelectViewDemo.app */, 82 | B64D7BD31A00EAB6004DC2BA /* SGPopSelectViewDemoTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | B64D7BBC1A00EAB6004DC2BA /* SGPopSelectView */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | B6A737511A010E5400537311 /* sg_pop_images.xcassets */, 91 | B6A737521A010E5400537311 /* SGPopSelectView.h */, 92 | B6A737531A010E5400537311 /* SGPopSelectView.m */, 93 | ); 94 | name = SGPopSelectView; 95 | path = ../classes; 96 | sourceTree = ""; 97 | }; 98 | B64D7BBD1A00EAB6004DC2BA /* Supporting Files */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | B6A7375C1A010F3400537311 /* main.m */, 102 | B64D7BBE1A00EAB6004DC2BA /* Info.plist */, 103 | ); 104 | name = "Supporting Files"; 105 | sourceTree = ""; 106 | }; 107 | B64D7BD61A00EAB6004DC2BA /* SGPopSelectViewTests */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | B64D7BD91A00EAB6004DC2BA /* SGPopSelectViewTests.m */, 111 | B64D7BD71A00EAB6004DC2BA /* Supporting Files */, 112 | ); 113 | path = SGPopSelectViewTests; 114 | sourceTree = ""; 115 | }; 116 | B64D7BD71A00EAB6004DC2BA /* Supporting Files */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | B64D7BD81A00EAB6004DC2BA /* Info.plist */, 120 | ); 121 | name = "Supporting Files"; 122 | sourceTree = ""; 123 | }; 124 | B64D7BE31A00EACB004DC2BA /* SGPopSelectViewDemo */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | B64D7BC11A00EAB6004DC2BA /* AppDelegate.h */, 128 | B64D7BC21A00EAB6004DC2BA /* AppDelegate.m */, 129 | B64D7BC41A00EAB6004DC2BA /* ViewController.h */, 130 | B64D7BC51A00EAB6004DC2BA /* ViewController.m */, 131 | B64D7BCA1A00EAB6004DC2BA /* Images.xcassets */, 132 | B6A737561A010F1500537311 /* Main.storyboard */, 133 | B6A737591A010F2500537311 /* LaunchScreen.xib */, 134 | B64D7BBD1A00EAB6004DC2BA /* Supporting Files */, 135 | ); 136 | path = SGPopSelectViewDemo; 137 | sourceTree = ""; 138 | }; 139 | /* End PBXGroup section */ 140 | 141 | /* Begin PBXNativeTarget section */ 142 | B64D7BB91A00EAB6004DC2BA /* SGPopSelectViewDemo */ = { 143 | isa = PBXNativeTarget; 144 | buildConfigurationList = B64D7BDD1A00EAB6004DC2BA /* Build configuration list for PBXNativeTarget "SGPopSelectViewDemo" */; 145 | buildPhases = ( 146 | B64D7BB61A00EAB6004DC2BA /* Sources */, 147 | B64D7BB71A00EAB6004DC2BA /* Frameworks */, 148 | B64D7BB81A00EAB6004DC2BA /* Resources */, 149 | ); 150 | buildRules = ( 151 | ); 152 | dependencies = ( 153 | ); 154 | name = SGPopSelectViewDemo; 155 | productName = SGPopSelectView; 156 | productReference = B64D7BBA1A00EAB6004DC2BA /* SGPopSelectViewDemo.app */; 157 | productType = "com.apple.product-type.application"; 158 | }; 159 | B64D7BD21A00EAB6004DC2BA /* SGPopSelectViewDemoTests */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = B64D7BE01A00EAB6004DC2BA /* Build configuration list for PBXNativeTarget "SGPopSelectViewDemoTests" */; 162 | buildPhases = ( 163 | B64D7BCF1A00EAB6004DC2BA /* Sources */, 164 | B64D7BD01A00EAB6004DC2BA /* Frameworks */, 165 | B64D7BD11A00EAB6004DC2BA /* Resources */, 166 | ); 167 | buildRules = ( 168 | ); 169 | dependencies = ( 170 | B64D7BD51A00EAB6004DC2BA /* PBXTargetDependency */, 171 | ); 172 | name = SGPopSelectViewDemoTests; 173 | productName = SGPopSelectViewTests; 174 | productReference = B64D7BD31A00EAB6004DC2BA /* SGPopSelectViewDemoTests.xctest */; 175 | productType = "com.apple.product-type.bundle.unit-test"; 176 | }; 177 | /* End PBXNativeTarget section */ 178 | 179 | /* Begin PBXProject section */ 180 | B64D7BB21A00EAB6004DC2BA /* Project object */ = { 181 | isa = PBXProject; 182 | attributes = { 183 | LastUpgradeCheck = 0610; 184 | ORGANIZATIONNAME = azurelab; 185 | TargetAttributes = { 186 | B64D7BB91A00EAB6004DC2BA = { 187 | CreatedOnToolsVersion = 6.1; 188 | }; 189 | B64D7BD21A00EAB6004DC2BA = { 190 | CreatedOnToolsVersion = 6.1; 191 | TestTargetID = B64D7BB91A00EAB6004DC2BA; 192 | }; 193 | }; 194 | }; 195 | buildConfigurationList = B64D7BB51A00EAB6004DC2BA /* Build configuration list for PBXProject "SGPopSelectViewDemo" */; 196 | compatibilityVersion = "Xcode 3.2"; 197 | developmentRegion = English; 198 | hasScannedForEncodings = 0; 199 | knownRegions = ( 200 | en, 201 | Base, 202 | ); 203 | mainGroup = B64D7BB11A00EAB6004DC2BA; 204 | productRefGroup = B64D7BBB1A00EAB6004DC2BA /* Products */; 205 | projectDirPath = ""; 206 | projectRoot = ""; 207 | targets = ( 208 | B64D7BB91A00EAB6004DC2BA /* SGPopSelectViewDemo */, 209 | B64D7BD21A00EAB6004DC2BA /* SGPopSelectViewDemoTests */, 210 | ); 211 | }; 212 | /* End PBXProject section */ 213 | 214 | /* Begin PBXResourcesBuildPhase section */ 215 | B64D7BB81A00EAB6004DC2BA /* Resources */ = { 216 | isa = PBXResourcesBuildPhase; 217 | buildActionMask = 2147483647; 218 | files = ( 219 | B6A7375B1A010F2500537311 /* LaunchScreen.xib in Resources */, 220 | B64D7BCB1A00EAB6004DC2BA /* Images.xcassets in Resources */, 221 | B6A737541A010E5400537311 /* sg_pop_images.xcassets in Resources */, 222 | B6A737581A010F1500537311 /* Main.storyboard in Resources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | B64D7BD11A00EAB6004DC2BA /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | B64D7BB61A00EAB6004DC2BA /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | B6A737551A010E5400537311 /* SGPopSelectView.m in Sources */, 241 | B64D7BC61A00EAB6004DC2BA /* ViewController.m in Sources */, 242 | B6A7375D1A010F3400537311 /* main.m in Sources */, 243 | B64D7BC31A00EAB6004DC2BA /* AppDelegate.m in Sources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | B64D7BCF1A00EAB6004DC2BA /* Sources */ = { 248 | isa = PBXSourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | B64D7BDA1A00EAB6004DC2BA /* SGPopSelectViewTests.m in Sources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXSourcesBuildPhase section */ 256 | 257 | /* Begin PBXTargetDependency section */ 258 | B64D7BD51A00EAB6004DC2BA /* PBXTargetDependency */ = { 259 | isa = PBXTargetDependency; 260 | target = B64D7BB91A00EAB6004DC2BA /* SGPopSelectViewDemo */; 261 | targetProxy = B64D7BD41A00EAB6004DC2BA /* PBXContainerItemProxy */; 262 | }; 263 | /* End PBXTargetDependency section */ 264 | 265 | /* Begin PBXVariantGroup section */ 266 | B6A737561A010F1500537311 /* Main.storyboard */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | B6A737571A010F1500537311 /* Base */, 270 | ); 271 | name = Main.storyboard; 272 | sourceTree = ""; 273 | }; 274 | B6A737591A010F2500537311 /* LaunchScreen.xib */ = { 275 | isa = PBXVariantGroup; 276 | children = ( 277 | B6A7375A1A010F2500537311 /* Base */, 278 | ); 279 | name = LaunchScreen.xib; 280 | sourceTree = ""; 281 | }; 282 | /* End PBXVariantGroup section */ 283 | 284 | /* Begin XCBuildConfiguration section */ 285 | B64D7BDB1A00EAB6004DC2BA /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 290 | CLANG_CXX_LIBRARY = "libc++"; 291 | CLANG_ENABLE_MODULES = YES; 292 | CLANG_ENABLE_OBJC_ARC = YES; 293 | CLANG_WARN_BOOL_CONVERSION = YES; 294 | CLANG_WARN_CONSTANT_CONVERSION = YES; 295 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 296 | CLANG_WARN_EMPTY_BODY = YES; 297 | CLANG_WARN_ENUM_CONVERSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 300 | CLANG_WARN_UNREACHABLE_CODE = YES; 301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 302 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 303 | COPY_PHASE_STRIP = NO; 304 | ENABLE_STRICT_OBJC_MSGSEND = YES; 305 | GCC_C_LANGUAGE_STANDARD = gnu99; 306 | GCC_DYNAMIC_NO_PIC = NO; 307 | GCC_OPTIMIZATION_LEVEL = 0; 308 | GCC_PREPROCESSOR_DEFINITIONS = ( 309 | "DEBUG=1", 310 | "$(inherited)", 311 | ); 312 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 320 | MTL_ENABLE_DEBUG_INFO = YES; 321 | ONLY_ACTIVE_ARCH = YES; 322 | SDKROOT = iphoneos; 323 | }; 324 | name = Debug; 325 | }; 326 | B64D7BDC1A00EAB6004DC2BA /* Release */ = { 327 | isa = XCBuildConfiguration; 328 | buildSettings = { 329 | ALWAYS_SEARCH_USER_PATHS = NO; 330 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 331 | CLANG_CXX_LIBRARY = "libc++"; 332 | CLANG_ENABLE_MODULES = YES; 333 | CLANG_ENABLE_OBJC_ARC = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_CONSTANT_CONVERSION = YES; 336 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INT_CONVERSION = YES; 340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 341 | CLANG_WARN_UNREACHABLE_CODE = YES; 342 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 343 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 344 | COPY_PHASE_STRIP = YES; 345 | ENABLE_NS_ASSERTIONS = NO; 346 | ENABLE_STRICT_OBJC_MSGSEND = YES; 347 | GCC_C_LANGUAGE_STANDARD = gnu99; 348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 350 | GCC_WARN_UNDECLARED_SELECTOR = YES; 351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_VARIABLE = YES; 354 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 355 | MTL_ENABLE_DEBUG_INFO = NO; 356 | SDKROOT = iphoneos; 357 | VALIDATE_PRODUCT = YES; 358 | }; 359 | name = Release; 360 | }; 361 | B64D7BDE1A00EAB6004DC2BA /* Debug */ = { 362 | isa = XCBuildConfiguration; 363 | buildSettings = { 364 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 365 | INFOPLIST_FILE = "$(SRCROOT)/SGPopSelectViewDemo/Info.plist"; 366 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 367 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 368 | PRODUCT_NAME = SGPopSelectViewDemo; 369 | }; 370 | name = Debug; 371 | }; 372 | B64D7BDF1A00EAB6004DC2BA /* Release */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 376 | INFOPLIST_FILE = "$(SRCROOT)/SGPopSelectViewDemo/Info.plist"; 377 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 378 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 379 | PRODUCT_NAME = SGPopSelectViewDemo; 380 | }; 381 | name = Release; 382 | }; 383 | B64D7BE11A00EAB6004DC2BA /* Debug */ = { 384 | isa = XCBuildConfiguration; 385 | buildSettings = { 386 | BUNDLE_LOADER = "$(TEST_HOST)"; 387 | FRAMEWORK_SEARCH_PATHS = ( 388 | "$(SDKROOT)/Developer/Library/Frameworks", 389 | "$(inherited)", 390 | ); 391 | GCC_PREPROCESSOR_DEFINITIONS = ( 392 | "DEBUG=1", 393 | "$(inherited)", 394 | ); 395 | INFOPLIST_FILE = SGPopSelectViewTests/Info.plist; 396 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 398 | PRODUCT_NAME = SGPopSelectViewDemoTests; 399 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SGPopSelectViewDemo.app/SGPopSelectViewDemo"; 400 | }; 401 | name = Debug; 402 | }; 403 | B64D7BE21A00EAB6004DC2BA /* Release */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | BUNDLE_LOADER = "$(TEST_HOST)"; 407 | FRAMEWORK_SEARCH_PATHS = ( 408 | "$(SDKROOT)/Developer/Library/Frameworks", 409 | "$(inherited)", 410 | ); 411 | INFOPLIST_FILE = SGPopSelectViewTests/Info.plist; 412 | IPHONEOS_DEPLOYMENT_TARGET = 7.1; 413 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 414 | PRODUCT_NAME = SGPopSelectViewDemoTests; 415 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SGPopSelectViewDemo.app/SGPopSelectViewDemo"; 416 | }; 417 | name = Release; 418 | }; 419 | /* End XCBuildConfiguration section */ 420 | 421 | /* Begin XCConfigurationList section */ 422 | B64D7BB51A00EAB6004DC2BA /* Build configuration list for PBXProject "SGPopSelectViewDemo" */ = { 423 | isa = XCConfigurationList; 424 | buildConfigurations = ( 425 | B64D7BDB1A00EAB6004DC2BA /* Debug */, 426 | B64D7BDC1A00EAB6004DC2BA /* Release */, 427 | ); 428 | defaultConfigurationIsVisible = 0; 429 | defaultConfigurationName = Release; 430 | }; 431 | B64D7BDD1A00EAB6004DC2BA /* Build configuration list for PBXNativeTarget "SGPopSelectViewDemo" */ = { 432 | isa = XCConfigurationList; 433 | buildConfigurations = ( 434 | B64D7BDE1A00EAB6004DC2BA /* Debug */, 435 | B64D7BDF1A00EAB6004DC2BA /* Release */, 436 | ); 437 | defaultConfigurationIsVisible = 0; 438 | defaultConfigurationName = Release; 439 | }; 440 | B64D7BE01A00EAB6004DC2BA /* Build configuration list for PBXNativeTarget "SGPopSelectViewDemoTests" */ = { 441 | isa = XCConfigurationList; 442 | buildConfigurations = ( 443 | B64D7BE11A00EAB6004DC2BA /* Debug */, 444 | B64D7BE21A00EAB6004DC2BA /* Release */, 445 | ); 446 | defaultConfigurationIsVisible = 0; 447 | defaultConfigurationName = Release; 448 | }; 449 | /* End XCConfigurationList section */ 450 | }; 451 | rootObject = B64D7BB21A00EAB6004DC2BA /* Project object */; 452 | } 453 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. 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 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/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 | 30 | 39 | 48 | 60 | 69 | 81 | 90 | 102 | 111 | 117 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.sagi.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "SGPopSelectView.h" 11 | 12 | @interface ViewController () 13 | @property (nonatomic, strong) NSArray *selections; 14 | @property (nonatomic, strong) SGPopSelectView *popView; 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | self.selections = @[@"Shake It Off",@"All About that Bass",@"Animals",@"Take Me To Church",@"Out Of The Woods",@"Centuries",@"I'm Not the Only One",@"Burnin' It Down"]; 23 | self.popView = [[SGPopSelectView alloc] init]; 24 | self.popView.selections = self.selections; 25 | __weak typeof(self) weakSelf = self; 26 | self.popView.selectedHandle = ^(NSInteger selectedIndex){ 27 | NSLog(@"selected index %ld, content is %@", selectedIndex, weakSelf.selections[selectedIndex]); 28 | }; 29 | } 30 | 31 | - (void)didReceiveMemoryWarning { 32 | [super didReceiveMemoryWarning]; 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | - (IBAction)showAction:(id)sender { 37 | CGPoint p = [(UIButton *)sender center]; 38 | [self.popView showFromView:self.view atPoint:p animated:YES]; 39 | } 40 | 41 | - (IBAction)tapAction:(UIGestureRecognizer *)sender { 42 | [self.popView hide:YES]; 43 | } 44 | 45 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 46 | { 47 | CGPoint p = [gestureRecognizer locationInView:self.view]; 48 | if (self.popView.visible && CGRectContainsPoint(self.popView.frame, p)) { 49 | return NO; 50 | } 51 | return YES; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. 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 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.sagi.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SGPopSelectView/SGPopSelectViewTests/SGPopSelectViewTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGPopSelectViewTests.m 3 | // SGPopSelectViewTests 4 | // 5 | // Created by Sagi on 14-10-29. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface SGPopSelectViewTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation SGPopSelectViewTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /classes/SGPopSelectView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGPopSelectView.h 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-28. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void (^PopViewSelectedHandle) (NSInteger selectedIndex); 12 | 13 | @interface SGPopSelectView : UIView 14 | @property (nonatomic, strong) NSArray *selections; 15 | @property (nonatomic, copy) PopViewSelectedHandle selectedHandle; 16 | @property (nonatomic, readonly) BOOL visible; 17 | 18 | - (instancetype)init; 19 | - (void)showFromView:(UIView*)view atPoint:(CGPoint)point animated:(BOOL)animated; 20 | - (void)hide:(BOOL)animated; 21 | @end 22 | -------------------------------------------------------------------------------- /classes/SGPopSelectView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGPopSelectView.m 3 | // SGPopSelectView 4 | // 5 | // Created by Sagi on 14-10-28. 6 | // Copyright (c) 2014年 azurelab. All rights reserved. 7 | // 8 | 9 | #import "SGPopSelectView.h" 10 | 11 | #define SGPOP_DEFAULT_FONT_SIZE 13 12 | #define SGPOP_DEFAULT_ROW_HEIHGT 30 13 | #define SGPOP_DEFAULT_MAX_HEIGHT 200 14 | 15 | @interface SGPopSelectView () 16 | @property (nonatomic, strong) UITableView *tableView; 17 | // data 18 | @property (nonatomic, assign) NSInteger selectedIndex; 19 | @end 20 | 21 | @implementation SGPopSelectView 22 | 23 | - (instancetype)init 24 | { 25 | self = [super initWithFrame:CGRectZero]; 26 | if (self) { 27 | _selectedIndex = NSNotFound; 28 | 29 | self.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95]; 30 | self.layer.cornerRadius = 8; 31 | self.layer.masksToBounds = NO; 32 | 33 | _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 34 | _tableView.backgroundColor = [UIColor clearColor]; 35 | _tableView.backgroundView = nil; 36 | _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 37 | _tableView.dataSource = self; 38 | _tableView.delegate = self; 39 | [self addSubview:_tableView]; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)layoutSubviews 45 | { 46 | [super layoutSubviews]; 47 | self.tableView.frame = self.bounds; 48 | self.layer.shadowColor = [UIColor blackColor].CGColor; 49 | self.layer.shadowOffset = CGSizeMake(0, 0); 50 | self.layer.shadowRadius = 4; 51 | self.layer.shadowOpacity = 0.2; 52 | self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; 53 | } 54 | 55 | - (void)setSelectedHandle:(PopViewSelectedHandle)handle 56 | { 57 | _selectedHandle = handle; 58 | } 59 | 60 | - (void)showFromView:(UIView *)view atPoint:(CGPoint)point animated:(BOOL)animated 61 | { 62 | if (self.visible) { 63 | [self removeFromSuperview]; 64 | } 65 | [view addSubview:self]; 66 | [self _setupFrameWithSuperView:view atPoint:point]; 67 | [self _showFromView:view animated:animated]; 68 | } 69 | 70 | - (void)hide:(BOOL)animated 71 | { 72 | [self _hideWithAnimated:animated]; 73 | } 74 | 75 | - (BOOL)visible 76 | { 77 | if (self.superview) { 78 | return YES; 79 | } 80 | return NO; 81 | } 82 | 83 | - (void)setSelections:(NSArray *)selections 84 | { 85 | _selections = selections; 86 | _selectedIndex = NSNotFound; 87 | [_tableView reloadData]; 88 | } 89 | 90 | #pragma mark - Private Methods 91 | 92 | static CAAnimation* _showAnimation() 93 | { 94 | CAKeyframeAnimation *transform = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; 95 | NSMutableArray *values = [NSMutableArray array]; 96 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.95, 0.95, 1.0)]]; 97 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.05, 1.05, 1.0)]]; 98 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]]; 99 | transform.values = values; 100 | 101 | CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"]; 102 | [opacity setFromValue:@0.0]; 103 | [opacity setToValue:@1.0]; 104 | 105 | CAAnimationGroup *group = [CAAnimationGroup animation]; 106 | group.duration = 0.2; 107 | group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 108 | [group setAnimations:@[transform, opacity]]; 109 | return group; 110 | } 111 | 112 | static CAAnimation* _hideAnimation() 113 | { 114 | CAKeyframeAnimation *transform = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; 115 | NSMutableArray *values = [NSMutableArray array]; 116 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.05, 1.05, 1.0)]]; 117 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]]; 118 | [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.95, 0.95, 1.0)]]; 119 | transform.values = values; 120 | 121 | CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"]; 122 | [opacity setFromValue:@1.0]; 123 | [opacity setToValue:@0.0]; 124 | 125 | CAAnimationGroup *group = [CAAnimationGroup animation]; 126 | group.duration = 0.2; 127 | group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 128 | [group setAnimations:@[transform, opacity]]; 129 | return group; 130 | } 131 | 132 | - (void)_showFromView:(UIView *)view animated:(BOOL)animated 133 | { 134 | if (animated) { 135 | [CATransaction begin]; 136 | [CATransaction setCompletionBlock:^{ 137 | [self.tableView flashScrollIndicators]; 138 | }]; 139 | [self.layer addAnimation:_showAnimation() forKey:nil]; 140 | [CATransaction commit]; 141 | } 142 | } 143 | 144 | - (void)_hideWithAnimated:(BOOL)animated 145 | { 146 | if (animated) { 147 | [CATransaction begin]; 148 | [CATransaction setCompletionBlock:^{ 149 | [self.layer removeAnimationForKey:@"transform"]; 150 | [self.layer removeAnimationForKey:@"opacity"]; 151 | [self removeFromSuperview]; 152 | }]; 153 | [self.layer addAnimation:_hideAnimation() forKey:nil]; 154 | [CATransaction commit]; 155 | }else { 156 | [self removeFromSuperview]; 157 | } 158 | } 159 | 160 | - (void)_setupFrameWithSuperView:(UIView *)view atPoint:(CGPoint)point 161 | { 162 | CGFloat totalHeight = _selections.count * SGPOP_DEFAULT_ROW_HEIHGT; 163 | CGFloat height = totalHeight > SGPOP_DEFAULT_MAX_HEIGHT ? SGPOP_DEFAULT_MAX_HEIGHT : totalHeight; 164 | CGFloat width = [self _preferedWidth]; 165 | width = width > view.bounds.size.width * 0.9 ? view.bounds.size.width * 0.9 : width; 166 | 167 | CGFloat offsetX = ((point.x / view.bounds.size.width) - floor(point.x / view.bounds.size.width)) * view.bounds.size.width; 168 | CGFloat offsetY = ((point.y / view.bounds.size.height) - floor(point.y / view.bounds.size.height)) * view.bounds.size.height; 169 | 170 | CGFloat left = (offsetX + width) > view.bounds.size.width ? (point.x - offsetX + view.bounds.size.width - width - 10) : point.x; 171 | CGFloat y = point.y - height / 2; 172 | if (point.y - height / 2 < 20) { 173 | y = 20; 174 | }else if (offsetY + height / 2 > view.bounds.size.height - 10) { 175 | y = point.y - offsetY + view.bounds.size.height - height - 10; 176 | } 177 | self.frame = CGRectMake(left, y, width, height); 178 | } 179 | 180 | - (CGFloat)_preferedWidth 181 | { 182 | NSPredicate *maxLength = [NSPredicate predicateWithFormat:@"SELF.length == %@.@max.length", _selections]; 183 | NSString *maxString = [_selections filteredArrayUsingPredicate:maxLength][0]; 184 | CGFloat strWidth; 185 | if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) { 186 | strWidth = [maxString sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:SGPOP_DEFAULT_FONT_SIZE]}].width; 187 | }else { 188 | strWidth = [maxString sizeWithFont:[UIFont systemFontOfSize:SGPOP_DEFAULT_FONT_SIZE]].width; 189 | } 190 | return strWidth + 15 * 2 + 30; 191 | } 192 | 193 | #pragma mark - UITableview DataSource 194 | 195 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 196 | { 197 | return _selections.count; 198 | } 199 | 200 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 201 | { 202 | static NSString *cellId = @"SelectionCell"; 203 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 204 | if (cell == nil) { 205 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; 206 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 207 | cell.backgroundView = nil; 208 | cell.backgroundColor = [UIColor clearColor]; 209 | cell.textLabel.font = [UIFont systemFontOfSize:SGPOP_DEFAULT_FONT_SIZE]; 210 | cell.textLabel.textColor = [UIColor darkTextColor]; 211 | } 212 | if (_selectedIndex == indexPath.row) { 213 | cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"oval_selected"]]; 214 | }else { 215 | cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"oval_unselected"]]; 216 | } 217 | cell.textLabel.text = _selections[indexPath.row]; 218 | return cell; 219 | } 220 | 221 | #pragma mark - UITableview Delegate 222 | 223 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 224 | { 225 | return SGPOP_DEFAULT_ROW_HEIHGT; 226 | } 227 | 228 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 229 | { 230 | _selectedIndex = indexPath.row; 231 | [tableView reloadData]; 232 | 233 | if (_selectedHandle) { 234 | _selectedHandle(indexPath.row); 235 | } 236 | } 237 | 238 | 239 | @end 240 | -------------------------------------------------------------------------------- /classes/sg_pop_images.xcassets/oval_selected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "Oval 3.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /classes/sg_pop_images.xcassets/oval_selected.imageset/Oval 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGPopSelectView/15c8740c727f8e952063ed1cc82b4dbbf01addfc/classes/sg_pop_images.xcassets/oval_selected.imageset/Oval 3.png -------------------------------------------------------------------------------- /classes/sg_pop_images.xcassets/oval_unselected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "Oval 4.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /classes/sg_pop_images.xcassets/oval_unselected.imageset/Oval 4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGPopSelectView/15c8740c727f8e952063ed1cc82b4dbbf01addfc/classes/sg_pop_images.xcassets/oval_unselected.imageset/Oval 4.png -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGPopSelectView/15c8740c727f8e952063ed1cc82b4dbbf01addfc/demo.gif --------------------------------------------------------------------------------