diff --git a/Example/TBAlertControllerDemo.xcodeproj/project.pbxproj b/Example/TBAlertControllerDemo.xcodeproj/project.pbxproj index 11d6ed5..c15dee6 100644 --- a/Example/TBAlertControllerDemo.xcodeproj/project.pbxproj +++ b/Example/TBAlertControllerDemo.xcodeproj/project.pbxproj @@ -354,6 +354,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = TBAlertControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -366,6 +367,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = TBAlertControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/Contents.json b/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..2d9e074 --- /dev/null +++ b/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,67 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "8.0", + "subtype" : "736h", + "scale" : "3x" + }, + { + "orientation" : "landscape", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "8.0", + "subtype" : "736h", + "scale" : "3x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "8.0", + "subtype" : "667h", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "filename" : "background@2x.png", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "subtype" : "retina4", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "subtype" : "retina4", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/background@2x.png b/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/background@2x.png new file mode 100644 index 0000000..1c10240 Binary files /dev/null and b/Example/TBAlertControllerDemo/Assets.xcassets/LaunchImage.launchimage/background@2x.png differ diff --git a/Example/TBAlertControllerDemo/Base.lproj/LaunchScreen.storyboard b/Example/TBAlertControllerDemo/Base.lproj/LaunchScreen.storyboard index 2e721e1..323bd43 100644 --- a/Example/TBAlertControllerDemo/Base.lproj/LaunchScreen.storyboard +++ b/Example/TBAlertControllerDemo/Base.lproj/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,7 +16,6 @@ - diff --git a/Example/TBAlertControllerDemo/ConditionerView.xib b/Example/TBAlertControllerDemo/ConditionerView.xib index 13c361f..4e7d0e4 100644 --- a/Example/TBAlertControllerDemo/ConditionerView.xib +++ b/Example/TBAlertControllerDemo/ConditionerView.xib @@ -14,43 +14,43 @@ @@ -123,7 +123,7 @@ @@ -140,7 +140,7 @@ @@ -157,7 +157,7 @@ diff --git a/Example/TBAlertControllerDemo/Info.plist b/Example/TBAlertControllerDemo/Info.plist index 6905cc6..2468026 100644 --- a/Example/TBAlertControllerDemo/Info.plist +++ b/Example/TBAlertControllerDemo/Info.plist @@ -30,6 +30,8 @@ armv7 + UIRequiresFullScreen + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/README.md b/README.md index f35eb06..feed447 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ TBActionSheet is a custom action sheet. The default style is iOS9, you can make your own style. -**TBActionSheet supports autorotation** +**TBActionSheet supports autorotation**, but there is some bugs on iOS7 :( + +Here is a gif showing TBActionSheet's powerful individuation: ![](images/demo.gif) @@ -18,12 +20,28 @@ This repo also include `TBAlertController`, which unifies `UIAlertController`, ` BTW, TBActionSheet also suppots BLOCK now! -##CocoaPods +##Installation +###CocoaPods Please search TBActionSheet +###Manual + +Just drag the "Source" document folder into your project. + ##Usage +###TLDR + +To let TBActionSheet looks like WeChat style, you can set these properties of `TBActionShet` or it's `UIAppearance` like this : +``` +sheetWidth = MIN(kScreenWidth, kScreenHeight); +backgroundTransparentEnabled = NO; +rectCornerRadius = 0; +``` + +### More than what you want + The base usage is same to `UIActionSheet`. You can just replace `UIActionSheet` with `TBActionSheet`. If you want to customize your action sheet, just configure some properties. I believe the header file can tell you much more than me. ``` diff --git a/Source/TBActionSheet/TBActionSheet.m b/Source/TBActionSheet/TBActionSheet.m index afdd39f..7c21bac 100644 --- a/Source/TBActionSheet/TBActionSheet.m +++ b/Source/TBActionSheet/TBActionSheet.m @@ -16,8 +16,6 @@ const CGFloat bigFragment = 8; const CGFloat smallFragment = 0.5; - - const CGFloat headerVerticalSpace = 10; const CGFloat blurRadius = 0.7; @@ -402,6 +400,7 @@ - (void)setUpStyle { CGFloat containerHeight = self.actionContainer.bounds.size.height; UIImage *originalBackgroundImage = [self screenShotRect:CGRectMake(kContainerLeft, kScreenHeight-containerHeight, self.sheetWidth, containerHeight)]; + CGFloat heightLargerThanImage = containerHeight - originalBackgroundImage.size.height;// 计算 container 的高度超出截图的数值 if (!self.isBackgroundTransparentEnabled) { if (self.isBlurEffectEnabled) { @@ -461,13 +460,25 @@ - (void)setUpStyle [btn setCornerRadius:self.rectCornerRadius]; } + UIImage *(^cutOriginalBackgroundImageInRect)(CGRect frame) = ^UIImage *(CGRect sourceFrame) { + CGRect targetFrame; + if (heightLargerThanImage > 0) { + targetFrame = CGRectMake(sourceFrame.origin.x, sourceFrame.origin.y - heightLargerThanImage, sourceFrame.size.width, sourceFrame.size.height); + } + else { + targetFrame = sourceFrame; + } + UIImage *cuttedImage = [self cutFromImage:originalBackgroundImage inRect:targetFrame]; + return cuttedImage; + }; + //设置背景风格 if ([self hasHeader]) { self.actionContainer.header.tbRectCorner |= TBRectCornerTop; if (self.isBlurEffectEnabled && self.isBackgroundTransparentEnabled) { if (![self.actionContainer useSystemBlurEffectUnderView:self.actionContainer.header]) { - UIImage *cuttedImage = [self cutFromImage:originalBackgroundImage inRect:self.actionContainer.header.frame]; - UIImage *backgroundImage = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor]; + + UIImage *backgroundImage = [cutOriginalBackgroundImageInRect(self.actionContainer.header.frame) drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor]; self.actionContainer.header.image = backgroundImage; } } @@ -482,8 +493,7 @@ - (void)setUpStyle } if (self.isBlurEffectEnabled && self.isBackgroundTransparentEnabled) { if (![self.actionContainer useSystemBlurEffectUnderView:self.actionContainer.custom]) { - UIImage *cuttedImage = [self cutFromImage:originalBackgroundImage inRect:self.actionContainer.custom.frame]; - UIImage *backgroundImage = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor]; + UIImage *backgroundImage = [cutOriginalBackgroundImageInRect(self.actionContainer.custom.frame) drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor]; self.actionContainer.custom.image = backgroundImage; } } @@ -498,7 +508,7 @@ - (void)setUpStyle [self.buttons enumerateObjectsUsingBlock:^(TBActionButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (self.isBlurEffectEnabled && self.isBackgroundTransparentEnabled) { if (![self.actionContainer useSystemBlurEffectUnderView:obj]) { - UIImage *cuttedImage = [self cutFromImage:originalBackgroundImage inRect:obj.frame]; + UIImage *cuttedImage = cutOriginalBackgroundImageInRect(obj.frame); UIImage *backgroundImageNormal = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:self.ambientColor]; UIImage *backgroundImageHighlighted = [cuttedImage drn_boxblurImageWithBlur:blurRadius withTintColor:[UIColor colorWithWhite:0.5 alpha:0.5]]; [obj setBackgroundImage:backgroundImageNormal forState:UIControlStateNormal]; @@ -699,7 +709,8 @@ - (UIImage *)screenShotRect:(CGRect)aRect UIGraphicsBeginImageContext(view.bounds.size); if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { - if (view.frame.size.width >= 1 && view.frame.size.height >= 1 ) { // resolve iOS7 size crash + const CGFloat crashMagicNumber = 0.3;// size 小于0.3 在 iOS7 上会导致 crash + if (view.frame.size.width >= crashMagicNumber && view.frame.size.height >= crashMagicNumber ) { // resolve iOS7 size crash [view drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; } } diff --git a/TBActionSheet.podspec b/TBActionSheet.podspec index b2dd7a3..c1c393c 100644 --- a/TBActionSheet.podspec +++ b/TBActionSheet.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "TBActionSheet" -s.version = "1.4" +s.version = "1.4.1" s.summary = "A Custom UIActionSheet" s.description = <<-DESC TBActionSheet is a custom action sheet. The default style is iOS9, you can make your own style.