├── .gitignore ├── LICENSE ├── README.md ├── SGActionView.podspec ├── SGActionView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SGActionView ├── SGActionView.h ├── SGActionView.m ├── SGAlertMenu.h ├── SGAlertMenu.m ├── SGBaseMenu.h ├── SGBaseMenu.m ├── SGGridMenu.h ├── SGGridMenu.m ├── SGSheetMenu.h └── SGSheetMenu.m ├── SGActionViewDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── Main.storyboard ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── SGActionView-Info.plist ├── SGActionView-Prefix.pch ├── ViewController.h ├── ViewController.m ├── en.lproj │ └── InfoPlist.strings ├── icons │ ├── dropbox@2x.png │ ├── facebook@2x.png │ ├── googleplus@2x.png │ ├── linkedin@2x.png │ ├── pocket@2x.png │ ├── twitter@2x.png │ ├── wechat@2x.png │ └── weibo@2x.png └── main.m ├── alert.png ├── grid.png └── sheet.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 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 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /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 of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SGActionView 2 | ============ 3 | 4 | ## 介绍 5 | 6 | SGActionView提供三种弹出视图: 7 | 8 | * SGAlertMenu,类似于UIAlertView的提示框。 9 | ![alert](alert.png) 10 | * SGGridMenu,多用于选择服务、分享等操作,类似UIActivityViewController的功能 11 | ![grid](grid.png) 12 | * SGSheetMenu,一个选项列表,可以设置默认值。 13 | ![sheet](sheet.png) 14 | 15 | ## 使用 16 | 17 | 引入`SGActionView.h` 18 | 19 | 提示框: 20 | 21 | [SGActionView showAlertWithTitle:@"Title" 22 | message:@"Message" 23 | buttonTitle:@"Cancel" 24 | selectedHandle:nil]; 25 | 26 | 选项列表: 27 | 28 | [SGActionView showSheetWithTitle:@"Sheet View" 29 | itemTitles:@[ @"Wedding Bell", @"I'm Yours", @"When I Was Your Man" ] 30 | itemSubTitles:@[ @"Depapepe - Let's go!!!", @"Jason Mraz", @"Bruno Mars" ] 31 | selectedIndex:0 32 | selectedHandle:nil]; 33 | 34 | 分享: 35 | 36 | [SGActionView showGridMenuWithTitle:@"Grid View" 37 | itemTitles:@[ @"Facebook", @"Twitter", @"Google+", @"Linkedin", 38 | @"Weibo", @"WeChat", @"Pocket", @"Dropbox" ] 39 | images:@[ [UIImage imageNamed:@"facebook"], 40 | [UIImage imageNamed:@"twitter"], 41 | [UIImage imageNamed:@"googleplus"], 42 | [UIImage imageNamed:@"linkedin"], 43 | [UIImage imageNamed:@"weibo"], 44 | [UIImage imageNamed:@"wechat"], 45 | [UIImage imageNamed:@"pocket"], 46 | [UIImage imageNamed:@"dropbox"]] 47 | selectedHandle:nil]; 48 | 49 | ## Third Party Bindings 50 | 51 | ### React Native 52 | You may now use this library with [React Native](https://github.com/facebook/react-native) via the module [here](https://github.com/prscX/react-native-bottom-action-sheet) 53 | 54 | 55 | ## License 56 | The MIT License (MIT) 57 | 58 | Copyright (c) [2014] [Sagi] 59 | 60 | Permission is hereby granted, free of charge, to any person obtaining a copy 61 | of this software and associated documentation files (the "Software"), to deal 62 | in the Software without restriction, including without limitation the rights 63 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 64 | copies of the Software, and to permit persons to whom the Software is 65 | furnished to do so, subject to the following conditions: 66 | 67 | The above copyright notice and this permission notice shall be included in all 68 | copies or substantial portions of the Software. 69 | 70 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 71 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 72 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 73 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 74 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 75 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 76 | SOFTWARE. 77 | -------------------------------------------------------------------------------- /SGActionView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SGActionView" 3 | s.version = "0.0.1" 4 | s.summary = "Combination alert view, table, and share view." 5 | s.description = "Combination alert view, table, and share view. 3 in one." 6 | s.homepage = "https://github.com/sagiwei/SGActionView" 7 | s.license = { :type => "MIT", :file => "README.markdown" } 8 | s.author = { "sagiwei" => "sagiwei@gmail.com" } 9 | 10 | s.source = { :git => "https://github.com/sagiwei/SGActionView.git", :commit => "7dbe145923b7481bddc6e3487742e6e35e4c5e64" } 11 | s.source_files = "SGActionView/*.{h,m}" 12 | 13 | s.platform = :ios, '6.0' 14 | s.framework = 'UIKit', 'CoreGraphics' 15 | s.requires_arc = true 16 | end 17 | -------------------------------------------------------------------------------- /SGActionView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B6B6E88B18601DD100625D83 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6B6E88A18601DD100625D83 /* Foundation.framework */; }; 11 | B6B6E88D18601DD100625D83 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6B6E88C18601DD100625D83 /* CoreGraphics.framework */; }; 12 | B6B6E88F18601DD100625D83 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6B6E88E18601DD100625D83 /* UIKit.framework */; }; 13 | B6B6E89518601DD100625D83 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6B6E89318601DD100625D83 /* InfoPlist.strings */; }; 14 | B6B6E89718601DD100625D83 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B6B6E89618601DD100625D83 /* main.m */; }; 15 | B6B6E89B18601DD100625D83 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B6B6E89A18601DD100625D83 /* AppDelegate.m */; }; 16 | B6B6E89E18601DD100625D83 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B6B6E89C18601DD100625D83 /* Main.storyboard */; }; 17 | B6B6E8A318601DD100625D83 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B6B6E8A218601DD100625D83 /* Images.xcassets */; }; 18 | B6B6E8C118601E8400625D83 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B6B6E8C018601E8400625D83 /* ViewController.m */; }; 19 | B6C203641860233D009C48C9 /* SGActionView.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C2035B1860233D009C48C9 /* SGActionView.m */; }; 20 | B6C203651860233D009C48C9 /* SGAlertMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C2035D1860233D009C48C9 /* SGAlertMenu.m */; }; 21 | B6C203661860233D009C48C9 /* SGBaseMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C2035F1860233D009C48C9 /* SGBaseMenu.m */; }; 22 | B6C203671860233D009C48C9 /* SGGridMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C203611860233D009C48C9 /* SGGridMenu.m */; }; 23 | B6C203681860233D009C48C9 /* SGSheetMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = B6C203631860233D009C48C9 /* SGSheetMenu.m */; }; 24 | B6C20372186027A4009C48C9 /* dropbox@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036A186027A4009C48C9 /* dropbox@2x.png */; }; 25 | B6C20373186027A4009C48C9 /* facebook@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036B186027A4009C48C9 /* facebook@2x.png */; }; 26 | B6C20374186027A4009C48C9 /* googleplus@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036C186027A4009C48C9 /* googleplus@2x.png */; }; 27 | B6C20375186027A4009C48C9 /* linkedin@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036D186027A4009C48C9 /* linkedin@2x.png */; }; 28 | B6C20376186027A4009C48C9 /* pocket@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036E186027A4009C48C9 /* pocket@2x.png */; }; 29 | B6C20377186027A4009C48C9 /* twitter@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C2036F186027A4009C48C9 /* twitter@2x.png */; }; 30 | B6C20378186027A4009C48C9 /* wechat@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C20370186027A4009C48C9 /* wechat@2x.png */; }; 31 | B6C20379186027A4009C48C9 /* weibo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6C20371186027A4009C48C9 /* weibo@2x.png */; }; 32 | /* End PBXBuildFile section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | B6B6E88718601DD100625D83 /* SGActionView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SGActionView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | B6B6E88A18601DD100625D83 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 37 | B6B6E88C18601DD100625D83 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 38 | B6B6E88E18601DD100625D83 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 39 | B6B6E89218601DD100625D83 /* SGActionView-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SGActionView-Info.plist"; sourceTree = ""; }; 40 | B6B6E89418601DD100625D83 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 41 | B6B6E89618601DD100625D83 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 42 | B6B6E89818601DD100625D83 /* SGActionView-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SGActionView-Prefix.pch"; sourceTree = ""; }; 43 | B6B6E89918601DD100625D83 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | B6B6E89A18601DD100625D83 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | B6B6E89D18601DD100625D83 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | B6B6E8A218601DD100625D83 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 47 | B6B6E8A918601DD100625D83 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 48 | B6B6E8BF18601E8400625D83 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 49 | B6B6E8C018601E8400625D83 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 50 | B6C2035A1860233D009C48C9 /* SGActionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGActionView.h; sourceTree = ""; }; 51 | B6C2035B1860233D009C48C9 /* SGActionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGActionView.m; sourceTree = ""; }; 52 | B6C2035C1860233D009C48C9 /* SGAlertMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGAlertMenu.h; sourceTree = ""; }; 53 | B6C2035D1860233D009C48C9 /* SGAlertMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGAlertMenu.m; sourceTree = ""; }; 54 | B6C2035E1860233D009C48C9 /* SGBaseMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGBaseMenu.h; sourceTree = ""; }; 55 | B6C2035F1860233D009C48C9 /* SGBaseMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGBaseMenu.m; sourceTree = ""; }; 56 | B6C203601860233D009C48C9 /* SGGridMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGGridMenu.h; sourceTree = ""; }; 57 | B6C203611860233D009C48C9 /* SGGridMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGGridMenu.m; sourceTree = ""; }; 58 | B6C203621860233D009C48C9 /* SGSheetMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGSheetMenu.h; sourceTree = ""; }; 59 | B6C203631860233D009C48C9 /* SGSheetMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGSheetMenu.m; sourceTree = ""; }; 60 | B6C2036A186027A4009C48C9 /* dropbox@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropbox@2x.png"; sourceTree = ""; }; 61 | B6C2036B186027A4009C48C9 /* facebook@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "facebook@2x.png"; sourceTree = ""; }; 62 | B6C2036C186027A4009C48C9 /* googleplus@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "googleplus@2x.png"; sourceTree = ""; }; 63 | B6C2036D186027A4009C48C9 /* linkedin@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "linkedin@2x.png"; sourceTree = ""; }; 64 | B6C2036E186027A4009C48C9 /* pocket@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pocket@2x.png"; sourceTree = ""; }; 65 | B6C2036F186027A4009C48C9 /* twitter@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "twitter@2x.png"; sourceTree = ""; }; 66 | B6C20370186027A4009C48C9 /* wechat@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wechat@2x.png"; sourceTree = ""; }; 67 | B6C20371186027A4009C48C9 /* weibo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "weibo@2x.png"; sourceTree = ""; }; 68 | /* End PBXFileReference section */ 69 | 70 | /* Begin PBXFrameworksBuildPhase section */ 71 | B6B6E88418601DD100625D83 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | B6B6E88D18601DD100625D83 /* CoreGraphics.framework in Frameworks */, 76 | B6B6E88F18601DD100625D83 /* UIKit.framework in Frameworks */, 77 | B6B6E88B18601DD100625D83 /* Foundation.framework in Frameworks */, 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | B64E7D04187652AD0072BE01 /* SGMenus */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | B6C2035E1860233D009C48C9 /* SGBaseMenu.h */, 88 | B6C2035F1860233D009C48C9 /* SGBaseMenu.m */, 89 | B6C2035C1860233D009C48C9 /* SGAlertMenu.h */, 90 | B6C2035D1860233D009C48C9 /* SGAlertMenu.m */, 91 | B6C203601860233D009C48C9 /* SGGridMenu.h */, 92 | B6C203611860233D009C48C9 /* SGGridMenu.m */, 93 | B6C203621860233D009C48C9 /* SGSheetMenu.h */, 94 | B6C203631860233D009C48C9 /* SGSheetMenu.m */, 95 | ); 96 | name = SGMenus; 97 | sourceTree = ""; 98 | }; 99 | B6B6E87E18601DD100625D83 = { 100 | isa = PBXGroup; 101 | children = ( 102 | B6C203591860233D009C48C9 /* SGActionView */, 103 | B6B6E89018601DD100625D83 /* SGActionViewDemo */, 104 | B6B6E88918601DD100625D83 /* Frameworks */, 105 | B6B6E88818601DD100625D83 /* Products */, 106 | ); 107 | sourceTree = ""; 108 | }; 109 | B6B6E88818601DD100625D83 /* Products */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | B6B6E88718601DD100625D83 /* SGActionView.app */, 113 | ); 114 | name = Products; 115 | sourceTree = ""; 116 | }; 117 | B6B6E88918601DD100625D83 /* Frameworks */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | B6B6E88A18601DD100625D83 /* Foundation.framework */, 121 | B6B6E88C18601DD100625D83 /* CoreGraphics.framework */, 122 | B6B6E88E18601DD100625D83 /* UIKit.framework */, 123 | B6B6E8A918601DD100625D83 /* XCTest.framework */, 124 | ); 125 | name = Frameworks; 126 | sourceTree = ""; 127 | }; 128 | B6B6E89018601DD100625D83 /* SGActionViewDemo */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | B6B6E89918601DD100625D83 /* AppDelegate.h */, 132 | B6B6E89A18601DD100625D83 /* AppDelegate.m */, 133 | B6B6E89C18601DD100625D83 /* Main.storyboard */, 134 | B6B6E8BF18601E8400625D83 /* ViewController.h */, 135 | B6B6E8C018601E8400625D83 /* ViewController.m */, 136 | B6B6E8A218601DD100625D83 /* Images.xcassets */, 137 | B6C20369186027A4009C48C9 /* icons */, 138 | B6B6E89118601DD100625D83 /* Supporting Files */, 139 | ); 140 | path = SGActionViewDemo; 141 | sourceTree = ""; 142 | }; 143 | B6B6E89118601DD100625D83 /* Supporting Files */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | B6B6E89218601DD100625D83 /* SGActionView-Info.plist */, 147 | B6B6E89318601DD100625D83 /* InfoPlist.strings */, 148 | B6B6E89618601DD100625D83 /* main.m */, 149 | B6B6E89818601DD100625D83 /* SGActionView-Prefix.pch */, 150 | ); 151 | name = "Supporting Files"; 152 | sourceTree = ""; 153 | }; 154 | B6C203591860233D009C48C9 /* SGActionView */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | B6C2035A1860233D009C48C9 /* SGActionView.h */, 158 | B6C2035B1860233D009C48C9 /* SGActionView.m */, 159 | B64E7D04187652AD0072BE01 /* SGMenus */, 160 | ); 161 | path = SGActionView; 162 | sourceTree = ""; 163 | }; 164 | B6C20369186027A4009C48C9 /* icons */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | B6C2036A186027A4009C48C9 /* dropbox@2x.png */, 168 | B6C2036B186027A4009C48C9 /* facebook@2x.png */, 169 | B6C2036C186027A4009C48C9 /* googleplus@2x.png */, 170 | B6C2036D186027A4009C48C9 /* linkedin@2x.png */, 171 | B6C2036E186027A4009C48C9 /* pocket@2x.png */, 172 | B6C2036F186027A4009C48C9 /* twitter@2x.png */, 173 | B6C20370186027A4009C48C9 /* wechat@2x.png */, 174 | B6C20371186027A4009C48C9 /* weibo@2x.png */, 175 | ); 176 | path = icons; 177 | sourceTree = ""; 178 | }; 179 | /* End PBXGroup section */ 180 | 181 | /* Begin PBXNativeTarget section */ 182 | B6B6E88618601DD100625D83 /* SGActionView */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = B6B6E8B918601DD100625D83 /* Build configuration list for PBXNativeTarget "SGActionView" */; 185 | buildPhases = ( 186 | B6B6E88318601DD100625D83 /* Sources */, 187 | B6B6E88418601DD100625D83 /* Frameworks */, 188 | B6B6E88518601DD100625D83 /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | ); 194 | name = SGActionView; 195 | productName = SGActionView; 196 | productReference = B6B6E88718601DD100625D83 /* SGActionView.app */; 197 | productType = "com.apple.product-type.application"; 198 | }; 199 | /* End PBXNativeTarget section */ 200 | 201 | /* Begin PBXProject section */ 202 | B6B6E87F18601DD100625D83 /* Project object */ = { 203 | isa = PBXProject; 204 | attributes = { 205 | LastUpgradeCheck = 0500; 206 | ORGANIZATIONNAME = AzureLab; 207 | }; 208 | buildConfigurationList = B6B6E88218601DD100625D83 /* Build configuration list for PBXProject "SGActionView" */; 209 | compatibilityVersion = "Xcode 3.2"; 210 | developmentRegion = English; 211 | hasScannedForEncodings = 0; 212 | knownRegions = ( 213 | en, 214 | Base, 215 | ); 216 | mainGroup = B6B6E87E18601DD100625D83; 217 | productRefGroup = B6B6E88818601DD100625D83 /* Products */; 218 | projectDirPath = ""; 219 | projectRoot = ""; 220 | targets = ( 221 | B6B6E88618601DD100625D83 /* SGActionView */, 222 | ); 223 | }; 224 | /* End PBXProject section */ 225 | 226 | /* Begin PBXResourcesBuildPhase section */ 227 | B6B6E88518601DD100625D83 /* Resources */ = { 228 | isa = PBXResourcesBuildPhase; 229 | buildActionMask = 2147483647; 230 | files = ( 231 | B6B6E8A318601DD100625D83 /* Images.xcassets in Resources */, 232 | B6C20373186027A4009C48C9 /* facebook@2x.png in Resources */, 233 | B6C20376186027A4009C48C9 /* pocket@2x.png in Resources */, 234 | B6C20374186027A4009C48C9 /* googleplus@2x.png in Resources */, 235 | B6C20377186027A4009C48C9 /* twitter@2x.png in Resources */, 236 | B6C20378186027A4009C48C9 /* wechat@2x.png in Resources */, 237 | B6B6E89518601DD100625D83 /* InfoPlist.strings in Resources */, 238 | B6B6E89E18601DD100625D83 /* Main.storyboard in Resources */, 239 | B6C20379186027A4009C48C9 /* weibo@2x.png in Resources */, 240 | B6C20375186027A4009C48C9 /* linkedin@2x.png in Resources */, 241 | B6C20372186027A4009C48C9 /* dropbox@2x.png in Resources */, 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | }; 245 | /* End PBXResourcesBuildPhase section */ 246 | 247 | /* Begin PBXSourcesBuildPhase section */ 248 | B6B6E88318601DD100625D83 /* Sources */ = { 249 | isa = PBXSourcesBuildPhase; 250 | buildActionMask = 2147483647; 251 | files = ( 252 | B6C203681860233D009C48C9 /* SGSheetMenu.m in Sources */, 253 | B6C203641860233D009C48C9 /* SGActionView.m in Sources */, 254 | B6C203651860233D009C48C9 /* SGAlertMenu.m in Sources */, 255 | B6C203671860233D009C48C9 /* SGGridMenu.m in Sources */, 256 | B6B6E8C118601E8400625D83 /* ViewController.m in Sources */, 257 | B6B6E89B18601DD100625D83 /* AppDelegate.m in Sources */, 258 | B6B6E89718601DD100625D83 /* main.m in Sources */, 259 | B6C203661860233D009C48C9 /* SGBaseMenu.m in Sources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | /* End PBXSourcesBuildPhase section */ 264 | 265 | /* Begin PBXVariantGroup section */ 266 | B6B6E89318601DD100625D83 /* InfoPlist.strings */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | B6B6E89418601DD100625D83 /* en */, 270 | ); 271 | name = InfoPlist.strings; 272 | sourceTree = ""; 273 | }; 274 | B6B6E89C18601DD100625D83 /* Main.storyboard */ = { 275 | isa = PBXVariantGroup; 276 | children = ( 277 | B6B6E89D18601DD100625D83 /* Base */, 278 | ); 279 | name = Main.storyboard; 280 | sourceTree = ""; 281 | }; 282 | /* End PBXVariantGroup section */ 283 | 284 | /* Begin XCBuildConfiguration section */ 285 | B6B6E8B718601DD100625D83 /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 291 | CLANG_CXX_LIBRARY = "libc++"; 292 | CLANG_ENABLE_MODULES = YES; 293 | CLANG_ENABLE_OBJC_ARC = YES; 294 | CLANG_WARN_BOOL_CONVERSION = YES; 295 | CLANG_WARN_CONSTANT_CONVERSION = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INT_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 302 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 303 | COPY_PHASE_STRIP = NO; 304 | GCC_C_LANGUAGE_STANDARD = gnu99; 305 | GCC_DYNAMIC_NO_PIC = NO; 306 | GCC_OPTIMIZATION_LEVEL = 0; 307 | GCC_PREPROCESSOR_DEFINITIONS = ( 308 | "DEBUG=1", 309 | "$(inherited)", 310 | ); 311 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 312 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 313 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 314 | GCC_WARN_UNDECLARED_SELECTOR = YES; 315 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 316 | GCC_WARN_UNUSED_FUNCTION = YES; 317 | GCC_WARN_UNUSED_VARIABLE = YES; 318 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 319 | ONLY_ACTIVE_ARCH = YES; 320 | SDKROOT = iphoneos; 321 | }; 322 | name = Debug; 323 | }; 324 | B6B6E8B818601DD100625D83 /* Release */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 336 | CLANG_WARN_EMPTY_BODY = YES; 337 | CLANG_WARN_ENUM_CONVERSION = YES; 338 | CLANG_WARN_INT_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 342 | COPY_PHASE_STRIP = YES; 343 | ENABLE_NS_ASSERTIONS = NO; 344 | GCC_C_LANGUAGE_STANDARD = gnu99; 345 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 346 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 347 | GCC_WARN_UNDECLARED_SELECTOR = YES; 348 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 349 | GCC_WARN_UNUSED_FUNCTION = YES; 350 | GCC_WARN_UNUSED_VARIABLE = YES; 351 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 352 | SDKROOT = iphoneos; 353 | VALIDATE_PRODUCT = YES; 354 | }; 355 | name = Release; 356 | }; 357 | B6B6E8BA18601DD100625D83 /* Debug */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 361 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 362 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 363 | GCC_PREFIX_HEADER = "SGActionViewDemo/SGActionView-Prefix.pch"; 364 | INFOPLIST_FILE = "$(SRCROOT)/SGActionViewDemo/SGActionView-Info.plist"; 365 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 366 | PRODUCT_NAME = "$(TARGET_NAME)"; 367 | WRAPPER_EXTENSION = app; 368 | }; 369 | name = Debug; 370 | }; 371 | B6B6E8BB18601DD100625D83 /* Release */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 375 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 376 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 377 | GCC_PREFIX_HEADER = "SGActionViewDemo/SGActionView-Prefix.pch"; 378 | INFOPLIST_FILE = "$(SRCROOT)/SGActionViewDemo/SGActionView-Info.plist"; 379 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 380 | PRODUCT_NAME = "$(TARGET_NAME)"; 381 | WRAPPER_EXTENSION = app; 382 | }; 383 | name = Release; 384 | }; 385 | /* End XCBuildConfiguration section */ 386 | 387 | /* Begin XCConfigurationList section */ 388 | B6B6E88218601DD100625D83 /* Build configuration list for PBXProject "SGActionView" */ = { 389 | isa = XCConfigurationList; 390 | buildConfigurations = ( 391 | B6B6E8B718601DD100625D83 /* Debug */, 392 | B6B6E8B818601DD100625D83 /* Release */, 393 | ); 394 | defaultConfigurationIsVisible = 0; 395 | defaultConfigurationName = Release; 396 | }; 397 | B6B6E8B918601DD100625D83 /* Build configuration list for PBXNativeTarget "SGActionView" */ = { 398 | isa = XCConfigurationList; 399 | buildConfigurations = ( 400 | B6B6E8BA18601DD100625D83 /* Debug */, 401 | B6B6E8BB18601DD100625D83 /* Release */, 402 | ); 403 | defaultConfigurationIsVisible = 0; 404 | defaultConfigurationName = Release; 405 | }; 406 | /* End XCConfigurationList section */ 407 | }; 408 | rootObject = B6B6E87F18601DD100625D83 /* Project object */; 409 | } 410 | -------------------------------------------------------------------------------- /SGActionView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SGActionView/SGActionView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGActionMenu.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-3. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * 弹出框样式 13 | */ 14 | typedef NS_ENUM(NSInteger, SGActionViewStyle){ 15 | SGActionViewStyleLight = 0, // 浅色背景,深色字体 16 | SGActionViewStyleDark // 深色背景,浅色字体 17 | }; 18 | 19 | typedef void(^SGMenuActionHandler)(NSInteger index); 20 | 21 | @interface SGActionView : UIView 22 | 23 | /** 24 | * 弹出框样式 25 | */ 26 | @property (nonatomic, assign) SGActionViewStyle style; 27 | 28 | /** 29 | * 获取单例 30 | */ 31 | + (SGActionView *)sharedActionView; 32 | 33 | /** 34 | * 提示框弹出层(单按钮) 35 | * 36 | * @param title 标题 37 | * @param message 提示内容 38 | * @param buttonTitle 按钮标题 39 | * @param handler 点击按钮时回调 40 | */ 41 | + (void)showAlertWithTitle:(NSString *)title 42 | message:(NSString *)message 43 | buttonTitle:(NSString *)buttonTitle 44 | selectedHandle:(SGMenuActionHandler)handler; 45 | 46 | /** 47 | * 提示框弹出层(双按钮) 48 | * 49 | * @param title 标题 50 | * @param message 提示内容 51 | * @param leftTitle 左按钮标题 52 | * @param rightTitle 右按钮标题 53 | * @param handler 回调, 0 为左, 1 为右 54 | */ 55 | + (void)showAlertWithTitle:(NSString *)title 56 | message:(NSString *)message 57 | leftButtonTitle:(NSString *)leftTitle 58 | rightButtonTitle:(NSString *)rightTitle 59 | selectedHandle:(SGMenuActionHandler)handler; 60 | 61 | 62 | /** 63 | * 选择列表弹出层 64 | * 65 | * @param title 标题 66 | * @param itemTitles 行标题 67 | * @param itemSubTitles 行子标题 68 | * @param handler 回调,index从 0 开始 69 | */ 70 | + (void)showSheetWithTitle:(NSString *)title 71 | itemTitles:(NSArray *)itemTitles 72 | selectedIndex:(NSInteger)selectedIndex 73 | selectedHandle:(SGMenuActionHandler)handler; 74 | 75 | 76 | /** 77 | * 选择列表弹出层(指定选中行) 78 | * 79 | * @param title 标题 80 | * @param itemTitles 行标题 81 | * @param itemSubTitles 行子标题 82 | * @param selectedIndex 选中行index 83 | * @param handler 回调,index从 0 开始 84 | */ 85 | + (void)showSheetWithTitle:(NSString *)title 86 | itemTitles:(NSArray *)itemTitles 87 | itemSubTitles:(NSArray *)itemSubTitles 88 | selectedIndex:(NSInteger)selectedIndex 89 | selectedHandle:(SGMenuActionHandler)handler; 90 | 91 | 92 | /** 93 | * 服务网格弹出层 94 | * 95 | * @param title 标题 96 | * @param itemTitles 元素标题 97 | * @param images 元素图标 98 | * @param handler 回调,元素index从 1 开始,0 为取消。 99 | */ 100 | + (void)showGridMenuWithTitle:(NSString *)title 101 | itemTitles:(NSArray *)itemTitles 102 | images:(NSArray *)images 103 | selectedHandle:(SGMenuActionHandler)handler; 104 | 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /SGActionView/SGActionView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGActionMenu.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-3. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "SGActionView.h" 10 | #import "SGAlertMenu.h" 11 | #import "SGSheetMenu.h" 12 | #import "SGGridMenu.h" 13 | #import 14 | 15 | 16 | @interface SGActionView () 17 | @property (nonatomic, strong) NSMutableArray *menus; 18 | @property (nonatomic, strong) CAAnimation *showMenuAnimation; 19 | @property (nonatomic, strong) CAAnimation *dismissMenuAnimation; 20 | @property (nonatomic, strong) CAAnimation *dimingAnimation; 21 | @property (nonatomic, strong) CAAnimation *lightingAnimation; 22 | // 点击背景取消 23 | @property (nonatomic, strong) UITapGestureRecognizer *tapGesture; 24 | @end 25 | 26 | @implementation SGActionView 27 | 28 | + (SGActionView *)sharedActionView 29 | { 30 | static SGActionView *actionView = nil; 31 | static dispatch_once_t onceToken; 32 | dispatch_once(&onceToken, ^{ 33 | CGRect rect = [[UIScreen mainScreen] bounds]; 34 | actionView = [[SGActionView alloc] initWithFrame:rect]; 35 | }); 36 | 37 | return actionView; 38 | } 39 | 40 | - (id)initWithFrame:(CGRect)frame 41 | { 42 | self = [super initWithFrame:frame]; 43 | if (self) { 44 | _menus = [NSMutableArray array]; 45 | 46 | _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; 47 | _tapGesture.delegate = self; 48 | [self addGestureRecognizer:_tapGesture]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)dealloc{ 54 | [self removeGestureRecognizer:_tapGesture]; 55 | } 56 | 57 | - (void)tapAction:(UITapGestureRecognizer *)tapGesture{ 58 | CGPoint touchPoint = [tapGesture locationInView:self]; 59 | // if (self.menus.count > 1) { 60 | // SGBaseMenu *menu = self.menus.lastObject; 61 | // if (!CGRectContainsPoint(menu.frame, touchPoint)) { 62 | // [menu removeFromSuperview]; 63 | // [self.menus removeLastObject]; 64 | // } 65 | // }else{ 66 | SGBaseMenu *menu = self.menus.lastObject; 67 | if (!CGRectContainsPoint(menu.frame, touchPoint)) { 68 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 69 | [self.menus removeObject:menu]; 70 | } 71 | // } 72 | } 73 | 74 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ 75 | if ([gestureRecognizer isEqual:self.tapGesture]) { 76 | CGPoint p = [gestureRecognizer locationInView:self]; 77 | SGBaseMenu *topMenu = self.menus.lastObject; 78 | if (CGRectContainsPoint(topMenu.frame, p)) { 79 | return NO; 80 | } 81 | } 82 | return YES; 83 | } 84 | 85 | #pragma mark - 86 | 87 | - (void)setMenu:(UIView *)menu animation:(BOOL)animated{ 88 | if (![self superview]) { 89 | UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 90 | [window addSubview:self]; 91 | } 92 | 93 | SGBaseMenu *topMenu = (SGBaseMenu *)menu; 94 | 95 | [self.menus makeObjectsPerformSelector:@selector(removeFromSuperview)]; 96 | [self.menus addObject:topMenu]; 97 | 98 | topMenu.style = self.style; 99 | [self addSubview:topMenu]; 100 | [topMenu layoutIfNeeded]; 101 | topMenu.frame = (CGRect){CGPointMake(0, self.bounds.size.height - topMenu.bounds.size.height), topMenu.bounds.size}; 102 | 103 | if (animated && self.menus.count == 1) { 104 | [CATransaction begin]; 105 | [CATransaction setAnimationDuration:0.2]; 106 | [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]]; 107 | [self.layer addAnimation:self.dimingAnimation forKey:@"diming"]; 108 | [topMenu.layer addAnimation:self.showMenuAnimation forKey:@"showMenu"]; 109 | [CATransaction commit]; 110 | } 111 | } 112 | 113 | - (void)dismissMenu:(SGBaseMenu *)menu Animated:(BOOL)animated 114 | { 115 | if ([self superview]) { 116 | [self.menus removeObject:menu]; 117 | if (animated && self.menus.count == 0) { 118 | [CATransaction begin]; 119 | [CATransaction setAnimationDuration:0.2]; 120 | [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; 121 | [CATransaction setCompletionBlock:^{ 122 | [self removeFromSuperview]; 123 | [menu removeFromSuperview]; 124 | }]; 125 | [self.layer addAnimation:self.lightingAnimation forKey:@"lighting"]; 126 | [menu.layer addAnimation:self.dismissMenuAnimation forKey:@"dismissMenu"]; 127 | [CATransaction commit]; 128 | }else{ 129 | [menu removeFromSuperview]; 130 | 131 | SGBaseMenu *topMenu = self.menus.lastObject; 132 | topMenu.style = self.style; 133 | [self addSubview:topMenu]; 134 | [topMenu layoutIfNeeded]; 135 | topMenu.frame = (CGRect){CGPointMake(0, self.bounds.size.height - topMenu.bounds.size.height), topMenu.bounds.size}; 136 | } 137 | } 138 | } 139 | 140 | #pragma mark - 141 | 142 | - (CAAnimation *)dimingAnimation 143 | { 144 | if (_dimingAnimation == nil) { 145 | CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; 146 | opacityAnimation.fromValue = (id)[[UIColor colorWithWhite:0.0 alpha:0.0] CGColor]; 147 | opacityAnimation.toValue = (id)[[UIColor colorWithWhite:0.0 alpha:0.4] CGColor]; 148 | [opacityAnimation setRemovedOnCompletion:NO]; 149 | [opacityAnimation setFillMode:kCAFillModeBoth]; 150 | _dimingAnimation = opacityAnimation; 151 | } 152 | return _dimingAnimation; 153 | } 154 | 155 | - (CAAnimation *)lightingAnimation 156 | { 157 | if (_lightingAnimation == nil ) { 158 | CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"]; 159 | opacityAnimation.fromValue = (id)[[UIColor colorWithWhite:0.0 alpha:0.4] CGColor]; 160 | opacityAnimation.toValue = (id)[[UIColor colorWithWhite:0.0 alpha:0.0] CGColor]; 161 | [opacityAnimation setRemovedOnCompletion:NO]; 162 | [opacityAnimation setFillMode:kCAFillModeBoth]; 163 | _lightingAnimation = opacityAnimation; 164 | } 165 | return _lightingAnimation; 166 | } 167 | 168 | - (CAAnimation *)showMenuAnimation 169 | { 170 | if (_showMenuAnimation == nil) { 171 | CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; 172 | CATransform3D t = CATransform3DIdentity; 173 | t.m34 = 1 / -500.0f; 174 | CATransform3D from = CATransform3DRotate(t, -30.0f * M_PI / 180.0f, 1, 0, 0); 175 | CATransform3D to = CATransform3DIdentity; 176 | [rotateAnimation setFromValue:[NSValue valueWithCATransform3D:from]]; 177 | [rotateAnimation setToValue:[NSValue valueWithCATransform3D:to]]; 178 | 179 | CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 180 | [scaleAnimation setFromValue:@0.9]; 181 | [scaleAnimation setToValue:@1.0]; 182 | 183 | CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; 184 | [positionAnimation setFromValue:[NSNumber numberWithFloat:50.0]]; 185 | [positionAnimation setToValue:[NSNumber numberWithFloat:0.0]]; 186 | 187 | CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 188 | [opacityAnimation setFromValue:@0.0]; 189 | [opacityAnimation setToValue:@1.0]; 190 | 191 | CAAnimationGroup *group = [CAAnimationGroup animation]; 192 | [group setAnimations:@[rotateAnimation, scaleAnimation, opacityAnimation, positionAnimation]]; 193 | [group setRemovedOnCompletion:NO]; 194 | [group setFillMode:kCAFillModeBoth]; 195 | _showMenuAnimation = group; 196 | } 197 | return _showMenuAnimation; 198 | } 199 | 200 | - (CAAnimation *)dismissMenuAnimation 201 | { 202 | if (_dismissMenuAnimation == nil) { 203 | CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; 204 | CATransform3D t = CATransform3DIdentity; 205 | t.m34 = 1 / -500.0f; 206 | CATransform3D from = CATransform3DIdentity; 207 | CATransform3D to = CATransform3DRotate(t, -30.0f * M_PI / 180.0f, 1, 0, 0); 208 | [rotateAnimation setFromValue:[NSValue valueWithCATransform3D:from]]; 209 | [rotateAnimation setToValue:[NSValue valueWithCATransform3D:to]]; 210 | 211 | CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 212 | [scaleAnimation setFromValue:@1.0]; 213 | [scaleAnimation setToValue:@0.9]; 214 | 215 | CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; 216 | [positionAnimation setFromValue:[NSNumber numberWithFloat:0.0]]; 217 | [positionAnimation setToValue:[NSNumber numberWithFloat:50.0]]; 218 | 219 | CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 220 | [opacityAnimation setFromValue:@1.0]; 221 | [opacityAnimation setToValue:@0.0]; 222 | 223 | CAAnimationGroup *group = [CAAnimationGroup animation]; 224 | [group setAnimations:@[rotateAnimation, scaleAnimation, opacityAnimation, positionAnimation]]; 225 | [group setRemovedOnCompletion:NO]; 226 | [group setFillMode:kCAFillModeBoth]; 227 | _dismissMenuAnimation = group; 228 | } 229 | return _dismissMenuAnimation; 230 | } 231 | 232 | #pragma mark - 233 | 234 | + (void)showAlertWithTitle:(NSString *)title 235 | message:(NSString *)message 236 | buttonTitle:(NSString *)buttonTitle 237 | selectedHandle:(SGMenuActionHandler)handler{ 238 | SGAlertMenu *menu = [[SGAlertMenu alloc] initWithTitle:title 239 | message:message 240 | buttonTitles:buttonTitle, nil]; 241 | [menu triggerSelectedAction:^(NSInteger index){ 242 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 243 | if (handler) { 244 | handler(index); 245 | } 246 | }]; 247 | [[SGActionView sharedActionView] setMenu:menu animation:YES]; 248 | } 249 | 250 | + (void)showAlertWithTitle:(NSString *)title 251 | message:(NSString *)message 252 | leftButtonTitle:(NSString *)leftTitle 253 | rightButtonTitle:(NSString *)rightTitle 254 | selectedHandle:(SGMenuActionHandler)handler{ 255 | SGAlertMenu *menu = [[SGAlertMenu alloc] initWithTitle:title 256 | message:message 257 | buttonTitles:leftTitle, rightTitle, nil]; 258 | [menu triggerSelectedAction:^(NSInteger index){ 259 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 260 | if (handler) { 261 | handler(index); 262 | } 263 | }]; 264 | [[SGActionView sharedActionView] setMenu:menu animation:YES]; 265 | } 266 | 267 | + (void)showSheetWithTitle:(NSString *)title 268 | itemTitles:(NSArray *)itemTitles 269 | selectedIndex:(NSInteger)selectedIndex 270 | selectedHandle:(SGMenuActionHandler)handler{ 271 | SGSheetMenu *menu = [[SGSheetMenu alloc] initWithTitle:title 272 | itemTitles:itemTitles]; 273 | menu.selectedItemIndex = selectedIndex; 274 | [menu triggerSelectedAction:^(NSInteger index){ 275 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 276 | if (handler) { 277 | handler(index); 278 | } 279 | }]; 280 | [[SGActionView sharedActionView] setMenu:menu animation:YES]; 281 | } 282 | 283 | + (void)showSheetWithTitle:(NSString *)title 284 | itemTitles:(NSArray *)itemTitles 285 | itemSubTitles:(NSArray *)itemSubTitles 286 | selectedIndex:(NSInteger)selectedIndex 287 | selectedHandle:(SGMenuActionHandler)handler{ 288 | SGSheetMenu *menu = [[SGSheetMenu alloc] initWithTitle:title 289 | itemTitles:itemTitles 290 | subTitles:itemSubTitles]; 291 | menu.selectedItemIndex = selectedIndex; 292 | [menu triggerSelectedAction:^(NSInteger index){ 293 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 294 | if (handler) { 295 | handler(index); 296 | } 297 | }]; 298 | [[SGActionView sharedActionView] setMenu:menu animation:YES]; 299 | } 300 | 301 | + (void)showGridMenuWithTitle:(NSString *)title 302 | itemTitles:(NSArray *)itemTitles 303 | images:(NSArray *)images 304 | selectedHandle:(SGMenuActionHandler)handler{ 305 | SGGridMenu *menu = [[SGGridMenu alloc] initWithTitle:title 306 | itemTitles:itemTitles 307 | images:images]; 308 | [menu triggerSelectedAction:^(NSInteger index){ 309 | [[SGActionView sharedActionView] dismissMenu:menu Animated:YES]; 310 | if (handler) { 311 | handler(index); 312 | } 313 | }]; 314 | [[SGActionView sharedActionView] setMenu:menu animation:YES]; 315 | } 316 | 317 | @end 318 | -------------------------------------------------------------------------------- /SGActionView/SGAlertMenu.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGAlertMenu.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-4. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SGBaseMenu.h" 11 | 12 | @interface SGAlertMenu : SGBaseMenu 13 | 14 | - (id)initWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSString *)buttonTitles,...; 15 | 16 | - (void)triggerSelectedAction:(void(^)(NSInteger))actionHandle; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /SGActionView/SGAlertMenu.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGAlertMenu.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-4. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SGAlertMenu.h" 11 | 12 | #define kMAX_ALERT_MESSAGE_HEIGHT 300 13 | 14 | @interface SGAlertMenu () 15 | @property (nonatomic, strong) UILabel *titleLabel; 16 | @property (nonatomic, strong) UILabel *messageLabel; 17 | @property (nonatomic, strong) NSMutableArray *actionButtons; 18 | @property (nonatomic, strong) SGMenuActionHandler actionHandle; 19 | @end 20 | 21 | @implementation SGAlertMenu 22 | 23 | - (id)initWithFrame:(CGRect)frame 24 | { 25 | self = [super initWithFrame:frame]; 26 | if (self) { 27 | _titleLabel = nil; 28 | _messageLabel = nil; 29 | _actionButtons = [NSMutableArray array]; 30 | } 31 | return self; 32 | } 33 | 34 | - (id)initWithTitle:(NSString *)title message:(NSString *)message buttonTitles:(NSString *)buttonTitles, ... 35 | { 36 | self = [self initWithFrame:[[UIScreen mainScreen] bounds]]; 37 | 38 | if (self) { 39 | NSMutableArray *actionButtonTitles = [NSMutableArray array]; 40 | if (buttonTitles) { 41 | [actionButtonTitles addObject:buttonTitles]; 42 | id eachObj; 43 | va_list argumentList; 44 | va_start(argumentList, buttonTitles); 45 | while ((eachObj = va_arg(argumentList, id))) { 46 | [actionButtonTitles addObject:eachObj]; 47 | } 48 | va_end(argumentList); 49 | } 50 | if (actionButtonTitles.count > 2) { 51 | [actionButtonTitles removeObjectsInRange:NSMakeRange(2, actionButtonTitles.count)]; 52 | } 53 | [self setupWithTitle:title message:message actionTitles:actionButtonTitles]; 54 | } 55 | return self; 56 | } 57 | 58 | - (void)setupWithTitle:(NSString *)title message:(NSString *)message actionTitles:(NSArray *)actionTitles; 59 | { 60 | self.backgroundColor = BaseMenuBackgroundColor(self.style); 61 | 62 | if (title) { 63 | _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 64 | _titleLabel.backgroundColor = [UIColor clearColor]; 65 | _titleLabel.font = [UIFont boldSystemFontOfSize:17]; 66 | _titleLabel.textAlignment = NSTextAlignmentCenter; 67 | _titleLabel.textColor = BaseMenuTextColor(self.style); 68 | _titleLabel.text = title; 69 | [self addSubview:_titleLabel]; 70 | } 71 | if (message) { 72 | _messageLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 73 | _messageLabel.backgroundColor = [UIColor clearColor]; 74 | _messageLabel.font = [UIFont systemFontOfSize:15]; 75 | _messageLabel.textAlignment = NSTextAlignmentLeft; 76 | _messageLabel.textColor = BaseMenuTextColor(self.style); 77 | _messageLabel.numberOfLines = 0; 78 | _messageLabel.text = message; 79 | [self addSubview:_messageLabel]; 80 | } 81 | for (int i=0; i 10 | #import "SGActionView.h" 11 | 12 | #define BaseMenuBackgroundColor(style) (style == SGActionViewStyleLight ? [UIColor colorWithWhite:1.0 alpha:1.0] : [UIColor colorWithWhite:0.2 alpha:1.0]) 13 | #define BaseMenuTextColor(style) (style == SGActionViewStyleLight ? [UIColor darkTextColor] : [UIColor lightTextColor]) 14 | #define BaseMenuActionTextColor(style) ([UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]) 15 | 16 | @interface SGButton : UIButton 17 | @end 18 | 19 | @interface SGBaseMenu : UIView{ 20 | SGActionViewStyle _style; 21 | } 22 | 23 | // if rounded top left/right corner, default is YES. 24 | @property (nonatomic, assign) BOOL roundedCorner; 25 | 26 | @property (nonatomic, assign) SGActionViewStyle style; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /SGActionView/SGBaseMenu.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGBaseMenu.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-18. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "SGBaseMenu.h" 10 | #import 11 | #include 12 | 13 | @implementation SGButton 14 | 15 | - (id)initWithFrame:(CGRect)frame 16 | { 17 | self = [super initWithFrame:frame]; 18 | if (self) { 19 | // Initialization code 20 | } 21 | return self; 22 | } 23 | 24 | - (void)setHighlighted:(BOOL)highlighted 25 | { 26 | if (highlighted) { 27 | self.backgroundColor = [UIColor lightGrayColor]; 28 | }else{ 29 | double delayInSeconds = 0.2; 30 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 31 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 32 | self.backgroundColor = [UIColor clearColor]; 33 | }); 34 | } 35 | } 36 | 37 | @end 38 | 39 | 40 | @implementation SGBaseMenu 41 | @synthesize style = _style; 42 | 43 | - (id)initWithFrame:(CGRect)frame 44 | { 45 | self = [super initWithFrame:frame]; 46 | if (self) { 47 | _style = SGActionViewStyleLight; 48 | self.roundedCorner = [self nicePerformance]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)setRoundedCorner:(BOOL)roundedCorner 54 | { 55 | if (roundedCorner) { 56 | UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds 57 | byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight 58 | cornerRadii:CGSizeMake(8, 8)]; 59 | CAShapeLayer *maskLayer = [CAShapeLayer layer]; 60 | maskLayer.frame = self.bounds; 61 | maskLayer.path = path.CGPath; 62 | self.layer.mask = maskLayer; 63 | }else{ 64 | self.layer.mask = nil; 65 | } 66 | _roundedCorner = roundedCorner; 67 | [self setNeedsDisplay]; 68 | } 69 | 70 | - (BOOL)nicePerformance{ 71 | size_t size; 72 | sysctlbyname("hw.machine", NULL, &size, NULL, 0); 73 | char *name = malloc(size); 74 | sysctlbyname("hw.machine", name, &size, NULL, 0); 75 | 76 | NSString *machine = [NSString stringWithCString:name encoding:NSUTF8StringEncoding]; 77 | 78 | free(name); 79 | 80 | BOOL b = YES; 81 | if ([machine hasPrefix:@"iPhone"]) { 82 | b = [[machine substringWithRange:NSMakeRange(6, 1)] intValue] >= 4; 83 | }else if ([machine hasPrefix:@"iPod"]){ 84 | b = [[machine substringWithRange:NSMakeRange(4, 1)] intValue] >= 5; 85 | }else if ([machine hasPrefix:@"iPad"]){ 86 | b = [[machine substringWithRange:NSMakeRange(4, 1)] intValue] >= 2; 87 | } 88 | 89 | return b; 90 | } 91 | 92 | /* 93 | // Only override drawRect: if you perform custom drawing. 94 | // An empty implementation adversely affects performance during animation. 95 | - (void)drawRect:(CGRect)rect 96 | { 97 | // Drawing code 98 | } 99 | */ 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /SGActionView/SGGridMenu.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGGridMenu.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-6. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SGBaseMenu.h" 11 | 12 | @interface SGGridMenu : SGBaseMenu 13 | 14 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles images:(NSArray *)images; 15 | 16 | - (void)triggerSelectedAction:(void(^)(NSInteger))actionHandle; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /SGActionView/SGGridMenu.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGGridMenu.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-6. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "SGGridMenu.h" 10 | #import 11 | 12 | #define kMAX_CONTENT_SCROLLVIEW_HEIGHT 400 13 | 14 | @interface SGGridItem : UIButton 15 | @property (nonatomic, weak) SGGridMenu *menu; 16 | @end 17 | 18 | @implementation SGGridItem 19 | 20 | - (id)initWithTitle:(NSString *)title image:(UIImage *)image 21 | { 22 | self = [super initWithFrame:CGRectZero]; 23 | if (self) { 24 | self.clipsToBounds = NO; 25 | 26 | self.titleLabel.font = [UIFont systemFontOfSize:13]; 27 | self.titleLabel.backgroundColor = [UIColor clearColor]; 28 | self.titleLabel.textAlignment = NSTextAlignmentCenter; 29 | [self setTitle:title forState:UIControlStateNormal]; 30 | [self setTitleColor:BaseMenuTextColor(self.menu.style) forState:UIControlStateNormal]; 31 | [self setImage:image forState:UIControlStateNormal]; 32 | } 33 | return self; 34 | } 35 | 36 | - (void)layoutSubviews 37 | { 38 | [super layoutSubviews]; 39 | 40 | float width = self.bounds.size.width; 41 | float height = self.bounds.size.height; 42 | 43 | CGRect imageRect = CGRectMake(width * 0.2, width * 0.2, width * 0.6, width * 0.6); 44 | self.imageView.frame = imageRect; 45 | 46 | float labelHeight = height - (imageRect.origin.y + imageRect.size.height); 47 | CGRect labelRect = CGRectMake(width * 0.05, imageRect.origin.y + imageRect.size.height, width * 0.9, labelHeight); 48 | self.titleLabel.frame = labelRect; 49 | } 50 | 51 | @end 52 | 53 | 54 | @interface SGGridMenu () 55 | @property (nonatomic, strong) UILabel *titleLabel; 56 | @property (nonatomic, strong) UIScrollView *contentScrollView; 57 | @property (nonatomic, strong) SGButton *cancelButton; 58 | @property (nonatomic, strong) NSArray *itemTitles; 59 | @property (nonatomic, strong) NSArray *itemImages; 60 | @property (nonatomic, strong) NSArray *items; 61 | @property (nonatomic, strong) void (^actionHandle)(NSInteger); 62 | @end 63 | 64 | @implementation SGGridMenu 65 | 66 | - (id)initWithFrame:(CGRect)frame 67 | { 68 | self = [super initWithFrame:frame]; 69 | if (self) { 70 | self.backgroundColor = BaseMenuBackgroundColor(self.style); 71 | 72 | _itemTitles = [NSArray array]; 73 | _itemImages = [NSArray array]; 74 | _items = [NSArray array]; 75 | 76 | _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 77 | _titleLabel.backgroundColor = [UIColor clearColor]; 78 | _titleLabel.font = [UIFont boldSystemFontOfSize:17]; 79 | _titleLabel.textAlignment = NSTextAlignmentCenter; 80 | _titleLabel.textColor = BaseMenuTextColor(self.style); 81 | [self addSubview:_titleLabel]; 82 | 83 | _contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectZero]; 84 | _contentScrollView.contentSize = _contentScrollView.bounds.size; 85 | _contentScrollView.showsHorizontalScrollIndicator = NO; 86 | _contentScrollView.showsVerticalScrollIndicator = YES; 87 | _contentScrollView.backgroundColor = [UIColor clearColor]; 88 | [self addSubview:_contentScrollView]; 89 | 90 | _cancelButton = [SGButton buttonWithType:UIButtonTypeCustom]; 91 | _cancelButton.clipsToBounds = YES; 92 | _cancelButton.titleLabel.font = [UIFont systemFontOfSize:17]; 93 | [_cancelButton setTitleColor:BaseMenuTextColor(self.style) forState:UIControlStateNormal]; 94 | [_cancelButton addTarget:self 95 | action:@selector(tapAction:) 96 | forControlEvents:UIControlEventTouchUpInside]; 97 | [_cancelButton setTitle:@"取 消" forState:UIControlStateNormal]; 98 | [self addSubview:_cancelButton]; 99 | } 100 | return self; 101 | } 102 | 103 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles images:(NSArray *)images 104 | { 105 | self = [self initWithFrame:[[UIScreen mainScreen] bounds]]; 106 | if (self) { 107 | NSInteger count = MIN(itemTitles.count, images.count); 108 | _titleLabel.text = title; 109 | _itemTitles = [itemTitles subarrayWithRange:NSMakeRange(0, count)]; 110 | _itemImages = [images subarrayWithRange:NSMakeRange(0, count)]; 111 | [self setupWithItemTitles:_itemTitles images:_itemImages]; 112 | } 113 | return self; 114 | } 115 | 116 | - (void)setupWithItemTitles:(NSArray *)titles images:(NSArray *)images 117 | { 118 | NSMutableArray *items = [NSMutableArray array]; 119 | for (int i=0; i kMAX_CONTENT_SCROLLVIEW_HEIGHT) { 175 | self.contentScrollView.bounds = (CGRect){CGPointZero, CGSizeMake(self.bounds.size.width, kMAX_CONTENT_SCROLLVIEW_HEIGHT)}; 176 | }else{ 177 | self.contentScrollView.bounds = (CGRect){CGPointZero, self.contentScrollView.contentSize}; 178 | } 179 | } 180 | 181 | #pragma mark - 182 | 183 | - (void)triggerSelectedAction:(void (^)(NSInteger))actionHandle 184 | { 185 | self.actionHandle = actionHandle; 186 | } 187 | 188 | #pragma mark - 189 | 190 | - (void)tapAction:(id)sender 191 | { 192 | if (self.actionHandle) { 193 | if ([sender isEqual:self.cancelButton]) { 194 | double delayInSeconds = 0.15; 195 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 196 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 197 | self.actionHandle(0); 198 | }); 199 | }else{ 200 | double delayInSeconds = 0.15; 201 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 202 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 203 | self.actionHandle([sender tag] + 1); 204 | }); 205 | } 206 | } 207 | } 208 | 209 | @end 210 | -------------------------------------------------------------------------------- /SGActionView/SGSheetMenu.h: -------------------------------------------------------------------------------- 1 | // 2 | // SGSheetMenu.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-6. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SGBaseMenu.h" 11 | 12 | @interface SGSheetMenu : SGBaseMenu 13 | 14 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles; 15 | 16 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles subTitles:(NSArray *)subTitles; 17 | 18 | @property (nonatomic, assign) NSUInteger selectedItemIndex; 19 | 20 | - (void)triggerSelectedAction:(void(^)(NSInteger))actionHandle; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /SGActionView/SGSheetMenu.m: -------------------------------------------------------------------------------- 1 | // 2 | // SGSheetMenu.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-9-6. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "SGSheetMenu.h" 10 | #import 11 | 12 | #define kMAX_SHEET_TABLE_HEIGHT 400 13 | 14 | @interface SGSheetMenu () 15 | @property (nonatomic, strong) UILabel *titleLabel; 16 | @property (nonatomic, strong) UITableView *tableView; 17 | @property (nonatomic, strong) NSArray *items; 18 | @property (nonatomic, strong) NSArray *subItems; 19 | 20 | @property (nonatomic, strong) void(^actionHandle)(NSInteger); 21 | @end 22 | 23 | @implementation SGSheetMenu 24 | 25 | - (id)initWithFrame:(CGRect)frame 26 | { 27 | self = [super initWithFrame:frame]; 28 | if (self) { 29 | self.backgroundColor = BaseMenuBackgroundColor(self.style); 30 | 31 | _selectedItemIndex = NSIntegerMax; 32 | _items = [NSArray array]; 33 | _subItems = [NSArray array]; 34 | 35 | _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 36 | _titleLabel.backgroundColor = [UIColor clearColor]; 37 | _titleLabel.font = [UIFont boldSystemFontOfSize:17]; 38 | _titleLabel.textAlignment = NSTextAlignmentCenter; 39 | _titleLabel.textColor = BaseMenuTextColor(self.style); 40 | [self addSubview:_titleLabel]; 41 | 42 | _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain]; 43 | _tableView.delegate = self; 44 | _tableView.dataSource = self; 45 | _tableView.backgroundColor = [UIColor clearColor]; 46 | _tableView.backgroundView = nil; 47 | _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 48 | [self addSubview:_tableView]; 49 | } 50 | return self; 51 | } 52 | 53 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles 54 | { 55 | self = [self initWithFrame:[[UIScreen mainScreen] bounds]]; 56 | if (self) { 57 | [self setupWithTitle:title items:itemTitles subItems:nil]; 58 | } 59 | return self; 60 | } 61 | 62 | - (id)initWithTitle:(NSString *)title itemTitles:(NSArray *)itemTitles subTitles:(NSArray *)subTitles 63 | { 64 | self = [self initWithFrame:[[UIScreen mainScreen] bounds]]; 65 | if (self) { 66 | [self setupWithTitle:title items:itemTitles subItems:subTitles]; 67 | } 68 | return self; 69 | } 70 | 71 | - (void)setupWithTitle:(NSString *)title items:(NSArray *)items subItems:(NSArray *)subItems; 72 | { 73 | _titleLabel.text = title; 74 | _items = items; 75 | _subItems = subItems; 76 | } 77 | 78 | - (void)setStyle:(SGActionViewStyle)style{ 79 | _style = style; 80 | 81 | self.backgroundColor = BaseMenuBackgroundColor(style); 82 | self.titleLabel.textColor = BaseMenuTextColor(style); 83 | } 84 | 85 | - (void)layoutSubviews 86 | { 87 | [super layoutSubviews]; 88 | 89 | float height = 0; 90 | float table_top_margin = 0; 91 | float table_bottom_margin = 10; 92 | 93 | self.titleLabel.frame = (CGRect){CGPointZero, CGSizeMake(self.bounds.size.width, 40)}; 94 | height += self.titleLabel.bounds.size.height; 95 | height += table_top_margin; 96 | 97 | [self.tableView reloadData]; 98 | [self.tableView layoutIfNeeded]; 99 | float contentHeight = self.tableView.contentSize.height; 100 | if (contentHeight > kMAX_SHEET_TABLE_HEIGHT) { 101 | contentHeight = kMAX_SHEET_TABLE_HEIGHT; 102 | self.tableView.scrollEnabled = YES; 103 | }else{ 104 | self.tableView.scrollEnabled = NO; 105 | } 106 | self.tableView.frame = CGRectMake(self.bounds.size.width * 0.05, height, self.bounds.size.width * 0.9, contentHeight); 107 | height += self.tableView.bounds.size.height; 108 | 109 | height += table_bottom_margin; 110 | 111 | self.bounds = (CGRect){CGPointZero, CGSizeMake(self.bounds.size.width, height)}; 112 | } 113 | 114 | #pragma mark - 115 | 116 | - (void)triggerSelectedAction:(void (^)(NSInteger))actionHandle 117 | { 118 | self.actionHandle = actionHandle; 119 | } 120 | 121 | #pragma mark - 122 | 123 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 124 | { 125 | return 1; 126 | } 127 | 128 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 129 | { 130 | return self.items.count; 131 | } 132 | 133 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 134 | { 135 | if (self.subItems.count > 0) { 136 | return 55; 137 | }else{ 138 | return 44; 139 | } 140 | } 141 | 142 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 143 | { 144 | static NSString *cellId = @"cellId"; 145 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 146 | if (cell == nil) { 147 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId]; 148 | cell.backgroundColor = [UIColor clearColor]; 149 | cell.textLabel.backgroundColor = [UIColor clearColor]; 150 | cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 151 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 152 | cell.textLabel.font = [UIFont systemFontOfSize:16]; 153 | cell.detailTextLabel.font = [UIFont systemFontOfSize:14]; 154 | cell.textLabel.textColor = BaseMenuTextColor(self.style); 155 | cell.detailTextLabel.textColor = BaseMenuTextColor(self.style); 156 | } 157 | cell.textLabel.text = self.items[indexPath.row]; 158 | if (self.subItems.count > indexPath.row) { 159 | NSString *subTitle = self.subItems[indexPath.row]; 160 | if (![subTitle isEqual:[NSNull null]]) { 161 | cell.detailTextLabel.text = subTitle; 162 | } 163 | } 164 | if (self.selectedItemIndex == indexPath.row) { 165 | cell.accessoryType = UITableViewCellAccessoryCheckmark; 166 | }else{ 167 | cell.accessoryType = UITableViewCellAccessoryNone; 168 | } 169 | 170 | return cell; 171 | } 172 | 173 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 174 | { 175 | if (self.selectedItemIndex != indexPath.row) { 176 | self.selectedItemIndex = indexPath.row; 177 | [tableView reloadData]; 178 | } 179 | if (self.actionHandle) { 180 | double delayInSeconds = 0.15; 181 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 182 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 183 | self.actionHandle(indexPath.row); 184 | }); 185 | } 186 | } 187 | 188 | @end 189 | -------------------------------------------------------------------------------- /SGActionViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-12-17. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /SGActionViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-12-17. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // 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. 22 | // 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. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // 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. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // 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. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 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 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /SGActionViewDemo/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 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 55 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 79 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 103 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 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 | -------------------------------------------------------------------------------- /SGActionViewDemo/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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /SGActionViewDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /SGActionViewDemo/SGActionView-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.azurelab.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SGActionViewDemo/SGActionView-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /SGActionViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-12-17. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SGActionViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-12-17. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "SGActionView.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl; 14 | 15 | @end 16 | 17 | @implementation ViewController 18 | 19 | - (id)initWithStyle:(UITableViewStyle)style 20 | { 21 | self = [super initWithStyle:style]; 22 | if (self) { 23 | // Custom initialization 24 | } 25 | return self; 26 | } 27 | 28 | - (void)viewDidLoad 29 | { 30 | [super viewDidLoad]; 31 | } 32 | 33 | - (void)didReceiveMemoryWarning 34 | { 35 | [super didReceiveMemoryWarning]; 36 | // Dispose of any resources that can be recreated. 37 | } 38 | 39 | #pragma mark - Table view data source 40 | 41 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 42 | { 43 | if (indexPath.section == 1) { 44 | NSInteger selected = self.segmentedControl.selectedSegmentIndex; 45 | [SGActionView sharedActionView].style = selected == 0 ? SGActionViewStyleLight : SGActionViewStyleDark; 46 | if (indexPath.row == 0) { 47 | [SGActionView showAlertWithTitle:@"Alert View" 48 | message:@"Just input your alert message here.\nUse '\\n' to create a line break.\nAuto height adjust your message." 49 | leftButtonTitle:@"Cancel" 50 | rightButtonTitle:@"OK" 51 | selectedHandle:nil]; 52 | }else if (indexPath.row == 1){ 53 | [SGActionView showSheetWithTitle:@"Sheet View" 54 | itemTitles:@[ @"Wedding Bell", @"I'm Yours", @"When I Was Your Man" ] 55 | itemSubTitles:@[ @"Depapepe - Let's go!!!", @"Jason Mraz", @"Bruno Mars" ] 56 | selectedIndex:0 57 | selectedHandle:nil]; 58 | }else if (indexPath.row == 2){ 59 | [SGActionView showGridMenuWithTitle:@"Grid View" 60 | itemTitles:@[ @"Facebook", @"Twitter", @"Google+", @"Linkedin", 61 | @"Weibo", @"WeChat", @"Pocket", @"Dropbox" ] 62 | images:@[ [UIImage imageNamed:@"facebook"], 63 | [UIImage imageNamed:@"twitter"], 64 | [UIImage imageNamed:@"googleplus"], 65 | [UIImage imageNamed:@"linkedin"], 66 | [UIImage imageNamed:@"weibo"], 67 | [UIImage imageNamed:@"wechat"], 68 | [UIImage imageNamed:@"pocket"], 69 | [UIImage imageNamed:@"dropbox"]] 70 | selectedHandle:nil]; 71 | } 72 | } 73 | double delayInSeconds = 0.2; 74 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 75 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 76 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 77 | }); 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /SGActionViewDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /SGActionViewDemo/icons/dropbox@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/dropbox@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/facebook@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/facebook@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/googleplus@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/googleplus@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/linkedin@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/linkedin@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/pocket@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/pocket@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/twitter@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/twitter@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/wechat@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/wechat@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/icons/weibo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/SGActionViewDemo/icons/weibo@2x.png -------------------------------------------------------------------------------- /SGActionViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SGActionView 4 | // 5 | // Created by Sagi on 13-12-17. 6 | // Copyright (c) 2013年 AzureLab. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/alert.png -------------------------------------------------------------------------------- /grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/grid.png -------------------------------------------------------------------------------- /sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiwei/SGActionView/a1df8c378774dafbd7005611301ff8babf5f46ae/sheet.png --------------------------------------------------------------------------------