diff --git a/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj b/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj index 04f565f..a72c64b 100644 --- a/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj +++ b/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj @@ -7,12 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 4A038CBF1BFB908300CA7921 /* LGPlusButtonsViewShared.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A038CBE1BFB908300CA7921 /* LGPlusButtonsViewShared.m */; }; 4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */; }; - 4A3F4B5A1AA8BA51006D9DAA /* PlusViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */; }; + 4A21D59D1BF731560023AE9E /* LGPlusButtonDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A21D59C1BF731560023AE9E /* LGPlusButtonDescription.m */; }; 4AF13A1F1BF3AD270037B073 /* LGPlusButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AF13A1C1BF3AD270037B073 /* LGPlusButton.m */; }; 4AF13A201BF3AD270037B073 /* LGPlusButtonsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AF13A1E1BF3AD270037B073 /* LGPlusButtonsView.m */; }; 847A899A1A9F298B004A8413 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89971A9F298B004A8413 /* NavigationController.m */; }; - 847A899B1A9F298B004A8413 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89991A9F298B004A8413 /* TableViewController.m */; }; 847A899E1A9F2C32004A8413 /* PlusScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A899D1A9F2C32004A8413 /* PlusScrollViewController.m */; }; 84C5B7CD1A9F22C800EEEB24 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C5B7CC1A9F22C800EEEB24 /* main.m */; }; 84C5B7D01A9F22C800EEEB24 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C5B7CF1A9F22C800EEEB24 /* AppDelegate.m */; }; @@ -20,17 +20,17 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4A038CBD1BFB908300CA7921 /* LGPlusButtonsViewShared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonsViewShared.h; sourceTree = ""; }; + 4A038CBE1BFB908300CA7921 /* LGPlusButtonsViewShared.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButtonsViewShared.m; sourceTree = ""; }; 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - 4A3F4B581AA8BA51006D9DAA /* PlusViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusViewController.h; sourceTree = ""; }; - 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlusViewController.m; sourceTree = ""; }; + 4A21D59B1BF731560023AE9E /* LGPlusButtonDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonDescription.h; sourceTree = ""; }; + 4A21D59C1BF731560023AE9E /* LGPlusButtonDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButtonDescription.m; sourceTree = ""; }; 4AF13A1B1BF3AD270037B073 /* LGPlusButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButton.h; sourceTree = ""; }; 4AF13A1C1BF3AD270037B073 /* LGPlusButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButton.m; sourceTree = ""; }; 4AF13A1D1BF3AD270037B073 /* LGPlusButtonsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonsView.h; sourceTree = ""; }; 4AF13A1E1BF3AD270037B073 /* LGPlusButtonsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButtonsView.m; sourceTree = ""; }; 847A89961A9F298B004A8413 /* NavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; 847A89971A9F298B004A8413 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; - 847A89981A9F298B004A8413 /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; - 847A89991A9F298B004A8413 /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; 847A899C1A9F2C32004A8413 /* PlusScrollViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusScrollViewController.h; sourceTree = ""; }; 847A899D1A9F2C32004A8413 /* PlusScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlusScrollViewController.m; sourceTree = ""; }; 84C5B7C71A9F22C800EEEB24 /* LGPlusButtonsViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LGPlusButtonsViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -52,31 +52,17 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 4A3F4B5D1AA8BDBA006D9DAA /* UIView */ = { - isa = PBXGroup; - children = ( - 4A3F4B581AA8BA51006D9DAA /* PlusViewController.h */, - 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */, - ); - name = UIView; - sourceTree = ""; - }; - 4A3F4B5E1AA8BDBE006D9DAA /* UIScrollView */ = { - isa = PBXGroup; - children = ( - 847A899C1A9F2C32004A8413 /* PlusScrollViewController.h */, - 847A899D1A9F2C32004A8413 /* PlusScrollViewController.m */, - ); - name = UIScrollView; - sourceTree = ""; - }; 4AF13A1A1BF3AD270037B073 /* LGPlusButtonsView */ = { isa = PBXGroup; children = ( - 4AF13A1B1BF3AD270037B073 /* LGPlusButton.h */, - 4AF13A1C1BF3AD270037B073 /* LGPlusButton.m */, 4AF13A1D1BF3AD270037B073 /* LGPlusButtonsView.h */, 4AF13A1E1BF3AD270037B073 /* LGPlusButtonsView.m */, + 4AF13A1B1BF3AD270037B073 /* LGPlusButton.h */, + 4AF13A1C1BF3AD270037B073 /* LGPlusButton.m */, + 4A21D59B1BF731560023AE9E /* LGPlusButtonDescription.h */, + 4A21D59C1BF731560023AE9E /* LGPlusButtonDescription.m */, + 4A038CBD1BFB908300CA7921 /* LGPlusButtonsViewShared.h */, + 4A038CBE1BFB908300CA7921 /* LGPlusButtonsViewShared.m */, ); name = LGPlusButtonsView; path = ../LGPlusButtonsView; @@ -114,10 +100,8 @@ 84C5B7CF1A9F22C800EEEB24 /* AppDelegate.m */, 847A89961A9F298B004A8413 /* NavigationController.h */, 847A89971A9F298B004A8413 /* NavigationController.m */, - 847A89981A9F298B004A8413 /* TableViewController.h */, - 847A89991A9F298B004A8413 /* TableViewController.m */, - 4A3F4B5D1AA8BDBA006D9DAA /* UIView */, - 4A3F4B5E1AA8BDBE006D9DAA /* UIScrollView */, + 847A899C1A9F2C32004A8413 /* PlusScrollViewController.h */, + 847A899D1A9F2C32004A8413 /* PlusScrollViewController.m */, 84C5B7D71A9F22C800EEEB24 /* Images.xcassets */, 84C5B7CA1A9F22C800EEEB24 /* Supporting Files */, 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */, @@ -204,11 +188,11 @@ buildActionMask = 2147483647; files = ( 4AF13A1F1BF3AD270037B073 /* LGPlusButton.m in Sources */, - 4A3F4B5A1AA8BA51006D9DAA /* PlusViewController.m in Sources */, + 4A21D59D1BF731560023AE9E /* LGPlusButtonDescription.m in Sources */, 847A899E1A9F2C32004A8413 /* PlusScrollViewController.m in Sources */, 847A899A1A9F298B004A8413 /* NavigationController.m in Sources */, 84C5B7D01A9F22C800EEEB24 /* AppDelegate.m in Sources */, - 847A899B1A9F298B004A8413 /* TableViewController.m in Sources */, + 4A038CBF1BFB908300CA7921 /* LGPlusButtonsViewShared.m in Sources */, 84C5B7CD1A9F22C800EEEB24 /* main.m in Sources */, 4AF13A201BF3AD270037B073 /* LGPlusButtonsView.m in Sources */, ); diff --git a/Demo/LGPlusButtonsViewDemo/AppDelegate.h b/Demo/LGPlusButtonsViewDemo/AppDelegate.h old mode 100644 new mode 100755 diff --git a/Demo/LGPlusButtonsViewDemo/AppDelegate.m b/Demo/LGPlusButtonsViewDemo/AppDelegate.m index 8ab40db..d49bf50 100644 --- a/Demo/LGPlusButtonsViewDemo/AppDelegate.m +++ b/Demo/LGPlusButtonsViewDemo/AppDelegate.m @@ -8,14 +8,14 @@ #import "AppDelegate.h" #import "NavigationController.h" -#import "TableViewController.h" +#import "PlusScrollViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - TableViewController *tableViewController = [TableViewController new]; - NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:tableViewController]; + PlusScrollViewController *viewController = [PlusScrollViewController new]; + NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:viewController]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = navigationController; diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera.png new file mode 100644 index 0000000..739f89a Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@2x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@2x.png new file mode 100644 index 0000000..6e42408 Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@2x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@3x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@3x.png new file mode 100644 index 0000000..dad7eee Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Camera@3x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Contents.json b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Contents.json new file mode 100644 index 0000000..ddaea54 --- /dev/null +++ b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Camera.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Camera.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Camera@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Camera@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Contents.json b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Contents.json new file mode 100644 index 0000000..efd0b20 --- /dev/null +++ b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Message.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Message@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Message@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message.png new file mode 100644 index 0000000..d191262 Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@2x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@2x.png new file mode 100644 index 0000000..e50a0d2 Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@2x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@3x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@3x.png new file mode 100644 index 0000000..97def72 Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Message.imageset/Message@3x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Contents.json b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Contents.json new file mode 100644 index 0000000..1e5a1eb --- /dev/null +++ b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "Picture.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "Picture@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "Picture@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture.png new file mode 100644 index 0000000..c8940ed Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@2x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@2x.png new file mode 100644 index 0000000..409909b Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@2x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@3x.png b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@3x.png new file mode 100644 index 0000000..6328cb6 Binary files /dev/null and b/Demo/LGPlusButtonsViewDemo/Images.xcassets/Picture.imageset/Picture@3x.png differ diff --git a/Demo/LGPlusButtonsViewDemo/Info.plist b/Demo/LGPlusButtonsViewDemo/Info.plist old mode 100644 new mode 100755 diff --git a/Demo/LGPlusButtonsViewDemo/NavigationController.h b/Demo/LGPlusButtonsViewDemo/NavigationController.h old mode 100644 new mode 100755 diff --git a/Demo/LGPlusButtonsViewDemo/NavigationController.m b/Demo/LGPlusButtonsViewDemo/NavigationController.m index 6b505ef..ae66839 100644 --- a/Demo/LGPlusButtonsViewDemo/NavigationController.m +++ b/Demo/LGPlusButtonsViewDemo/NavigationController.m @@ -21,7 +21,7 @@ - (void)viewDidLoad self.navigationBar.translucent = YES; self.navigationBar.barTintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; - self.navigationBar.tintColor = [UIColor colorWithWhite:1.f alpha:0.75]; + self.navigationBar.tintColor = [UIColor colorWithWhite:1.f alpha:1.f]; } - (BOOL)shouldAutorotate diff --git a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.h b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.h index 24b17e9..6b2c61e 100644 --- a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.h +++ b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.h @@ -10,6 +10,4 @@ @interface PlusScrollViewController : UIViewController -- (id)initWithTitle:(NSString *)title; - @end diff --git a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m index a69bdfc..f71646e 100644 --- a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m +++ b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m @@ -12,59 +12,183 @@ @interface PlusScrollViewController () @property (strong, nonatomic) UIScrollView *scrollView; -@property (strong, nonatomic) UILabel *textLabel; -@property (strong, nonatomic) LGPlusButtonsView *plusButtonsView; +@property (strong, nonatomic) UIView *exampleView; +@property (strong, nonatomic) LGPlusButtonsView *plusButtonsViewNavBar; +@property (strong, nonatomic) LGPlusButtonsView *plusButtonsViewMain; +@property (strong, nonatomic) LGPlusButtonsView *plusButtonsViewExample; @end @implementation PlusScrollViewController -- (id)initWithTitle:(NSString *)title +- (instancetype)init { self = [super init]; if (self) { - self.title = title; + self.title = @"LGPlusButtonsView"; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showHideButtonsAction)]; // ----- _scrollView = [UIScrollView new]; - _scrollView.backgroundColor = [UIColor whiteColor]; + _scrollView.backgroundColor = [UIColor lightGrayColor]; _scrollView.alwaysBounceVertical = YES; [self.view addSubview:_scrollView]; - _textLabel = [UILabel new]; - _textLabel.backgroundColor = [UIColor clearColor]; - _textLabel.text = @"UIScrollView"; - [_scrollView addSubview:_textLabel]; + _exampleView = [UIView new]; + _exampleView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.1]; + [_scrollView addSubview:_exampleView]; + } + return self; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; - _plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_scrollView - numberOfButtons:3 - showsPlusButton:YES - actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) + _plusButtonsViewMain = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:4 + firstButtonIsPlusButton:YES + showAfterInit:YES + actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) { - NSLog(@"%@, %@, %i", title, description, (int)index); - } - plusButtonActionHandler:nil]; - - [_plusButtonsView setButtonsTitles:@[@"+", @"1", @"2", @"3"] forState:UIControlStateNormal]; - [_plusButtonsView setDescriptionsTexts:@[@"", @"Button One description", @"Button Two description", @"Button Three description"]]; - _plusButtonsView.position = LGPlusButtonsViewPositionBottomRight; - _plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical; - _plusButtonsView.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal; - _plusButtonsView.plusButtonAnimationType = LGPlusButtonAnimationTypeRotate; - [_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO]; - [_plusButtonsView setButtonsImage:[UIImage imageNamed:@"Circle_Normal"] forState:UIControlStateNormal]; - [_plusButtonsView setButtonsImage:[UIImage imageNamed:@"Circle_Highlighted"] forState:UIControlStateHighlighted]; - [_plusButtonsView setButtonsLayerShadowColor:[UIColor blackColor] shadowOpacity:0.5 shadowOffset:CGSizeZero shadowRadius:2.f]; - //_plusButtonsView.alwaysVisible = YES; - //_plusButtonsView.hideButtonsOnScroll = YES; - //_plusButtonsView.scrollSensitivity = 0.f; - - [_plusButtonsView showAnimated:NO completionHandler:nil]; + NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); + + if (index == 0) + [_plusButtonsViewNavBar hideAnimated:YES completionHandler:nil]; + }]; + + _plusButtonsViewMain.observedScrollView = self.scrollView; + _plusButtonsViewMain.coverColor = [UIColor colorWithWhite:1.f alpha:0.7]; + _plusButtonsViewMain.position = LGPlusButtonsViewPositionBottomRight; + _plusButtonsViewMain.plusButtonAnimationType = LGPlusButtonAnimationTypeRotate; + + [_plusButtonsViewMain setButtonsTitles:@[@"+", @"", @"", @""] forState:UIControlStateNormal]; + [_plusButtonsViewMain setDescriptionsTexts:@[@"", @"Take a photo", @"Choose from gallery", @"Send a message"]]; + [_plusButtonsViewMain setButtonsImages:@[[NSNull new], [UIImage imageNamed:@"Camera"], [UIImage imageNamed:@"Picture"], [UIImage imageNamed:@"Message"]] + forState:UIControlStateNormal + forOrientation:LGPlusButtonsViewOrientationAll]; + + [_plusButtonsViewMain setButtonsAdjustsImageWhenHighlighted:NO]; + [_plusButtonsViewMain setButtonsBackgroundColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewMain setButtonsBackgroundColor:[UIColor colorWithRed:0.2 green:0.6 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; + [_plusButtonsViewMain setButtonsBackgroundColor:[UIColor colorWithRed:0.2 green:0.6 blue:1.f alpha:1.f] forState:UIControlStateHighlighted|UIControlStateSelected]; + [_plusButtonsViewMain setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewMain setButtonsLayerCornerRadius:44.f/2.f forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewMain setButtonsTitleFont:[UIFont boldSystemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewMain setButtonsLayerShadowColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.f]]; + [_plusButtonsViewMain setButtonsLayerShadowOpacity:0.5]; + [_plusButtonsViewMain setButtonsLayerShadowRadius:3.f]; + [_plusButtonsViewMain setButtonsLayerShadowOffset:CGSizeMake(0.f, 2.f)]; + [_plusButtonsViewMain setButtonAtIndex:0 size:CGSizeMake(56.f, 56.f) + forOrientation:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationAll)]; + [_plusButtonsViewMain setButtonAtIndex:0 layerCornerRadius:56.f/2.f + forOrientation:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationAll)]; + [_plusButtonsViewMain setButtonAtIndex:0 titleFont:[UIFont systemFontOfSize:40.f] + forOrientation:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationAll)]; + [_plusButtonsViewMain setButtonAtIndex:0 titleOffset:CGPointMake(0.f, -3.f) forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewMain setButtonAtIndex:1 backgroundColor:[UIColor colorWithRed:1.f green:0.f blue:0.5 alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewMain setButtonAtIndex:1 backgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted]; + [_plusButtonsViewMain setButtonAtIndex:2 backgroundColor:[UIColor colorWithRed:1.f green:0.5 blue:0.f alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewMain setButtonAtIndex:2 backgroundColor:[UIColor colorWithRed:1.f green:0.6 blue:0.2 alpha:1.f] forState:UIControlStateHighlighted]; + [_plusButtonsViewMain setButtonAtIndex:3 backgroundColor:[UIColor colorWithRed:0.f green:0.7 blue:0.f alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewMain setButtonAtIndex:3 backgroundColor:[UIColor colorWithRed:0.f green:0.8 blue:0.f alpha:1.f] forState:UIControlStateHighlighted]; + + [_plusButtonsViewMain setDescriptionsBackgroundColor:[UIColor whiteColor]]; + [_plusButtonsViewMain setDescriptionsTextColor:[UIColor blackColor]]; + [_plusButtonsViewMain setDescriptionsLayerShadowColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.f]]; + [_plusButtonsViewMain setDescriptionsLayerShadowOpacity:0.25]; + [_plusButtonsViewMain setDescriptionsLayerShadowRadius:1.f]; + [_plusButtonsViewMain setDescriptionsLayerShadowOffset:CGSizeMake(0.f, 1.f)]; + [_plusButtonsViewMain setDescriptionsLayerCornerRadius:6.f forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewMain setDescriptionsContentEdgeInsets:UIEdgeInsetsMake(4.f, 8.f, 4.f, 8.f) forOrientation:LGPlusButtonsViewOrientationAll]; + + for (NSUInteger i=1; i<=3; i++) + [_plusButtonsViewMain setButtonAtIndex:i offset:CGPointMake(-6.f, 0.f) + forOrientation:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationAll)]; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) + { + [_plusButtonsViewMain setButtonAtIndex:0 titleOffset:CGPointMake(0.f, -2.f) forOrientation:LGPlusButtonsViewOrientationLandscape]; + [_plusButtonsViewMain setButtonAtIndex:0 titleFont:[UIFont systemFontOfSize:32.f] forOrientation:LGPlusButtonsViewOrientationLandscape]; } - return self; + + [self.navigationController.view addSubview:_plusButtonsViewMain]; + + // ----- + + _plusButtonsViewNavBar = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 + firstButtonIsPlusButton:NO + showAfterInit:NO + actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) + { + NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); + }]; + + _plusButtonsViewNavBar.showHideOnScroll = NO; + _plusButtonsViewNavBar.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop; + _plusButtonsViewNavBar.position = LGPlusButtonsViewPositionTopRight; + + [_plusButtonsViewNavBar setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal]; + [_plusButtonsViewNavBar setDescriptionsTexts:@[@"Description 1", @"Description 2", @"Description 3"]]; + + [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont boldSystemFontOfSize:32.f] forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(52.f, 52.f) forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewNavBar setButtonsLayerCornerRadius:52.f/2.f forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.2 green:0.6 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; + [_plusButtonsViewNavBar setButtonsLayerShadowColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.f]]; + [_plusButtonsViewNavBar setButtonsLayerShadowOpacity:0.5]; + [_plusButtonsViewNavBar setButtonsLayerShadowRadius:3.f]; + [_plusButtonsViewNavBar setButtonsLayerShadowOffset:CGSizeMake(0.f, 2.f)]; + + [_plusButtonsViewNavBar setDescriptionsTextColor:[UIColor whiteColor]]; + [_plusButtonsViewNavBar setDescriptionsBackgroundColor:[UIColor colorWithWhite:0.f alpha:0.66]]; + [_plusButtonsViewNavBar setDescriptionsLayerCornerRadius:6.f forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewNavBar setDescriptionsContentEdgeInsets:UIEdgeInsetsMake(4.f, 8.f, 4.f, 8.f) forOrientation:LGPlusButtonsViewOrientationAll]; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) + { + [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationLandscape]; + [_plusButtonsViewNavBar setButtonsLayerCornerRadius:44.f/2.f forOrientation:LGPlusButtonsViewOrientationLandscape]; + [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationLandscape]; + } + + [self.scrollView addSubview:_plusButtonsViewNavBar]; + + // ----- + + _plusButtonsViewExample = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 + firstButtonIsPlusButton:YES + showAfterInit:YES + actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) + { + NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); + }]; + + _plusButtonsViewExample.position = LGPlusButtonsViewPositionBottomLeft; + _plusButtonsViewExample.plusButtonAnimationType = LGPlusButtonAnimationTypeCrossDissolve; + _plusButtonsViewExample.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolve; + + [_plusButtonsViewExample setButtonsTitles:@[@"+", @"1", @"2"] forState:UIControlStateNormal]; + [_plusButtonsViewExample setDescriptionsTexts:@[@"", @"Description 1", @"Description 2"]]; + + [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.f blue:0.5 alpha:1.f] forState:UIControlStateNormal]; + [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted]; + [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted|UIControlStateSelected]; + [_plusButtonsViewExample setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewExample setButtonsLayerBorderWidth:2.f]; + [_plusButtonsViewExample setButtonsLayerBorderColor:[UIColor colorWithWhite:0.9 alpha:1.f]]; + [_plusButtonsViewExample setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewExample setButtonAtIndex:0 titleOffset:CGPointMake(0.f, -2.f) forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewExample setButtonAtIndex:0 title:@"-" forState:UIControlStateSelected]; + + [_plusButtonsViewExample setDescriptionsTextColor:[UIColor whiteColor]]; + [_plusButtonsViewExample setDescriptionsFont:[UIFont boldSystemFontOfSize:18.f] forOrientation:LGPlusButtonsViewOrientationAll]; + [_plusButtonsViewExample setDescriptionsInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, 4.f) forOrientation:LGPlusButtonsViewOrientationAll]; + + [_exampleView addSubview:_plusButtonsViewExample]; } #pragma mark - Dealloc @@ -82,29 +206,27 @@ - (void)viewWillLayoutSubviews _scrollView.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height); - [_textLabel sizeToFit]; - _textLabel.center = CGPointMake(_scrollView.frame.size.width/2, 20.f+_textLabel.frame.size.height/2); - _textLabel.frame = CGRectIntegral(_textLabel.frame); + UIEdgeInsets contentInsets = _scrollView.contentInset; + contentInsets.top = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.frame.size.height; + _scrollView.contentInset = contentInsets; + _scrollView.scrollIndicatorInsets = contentInsets; - _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 3000.f); + _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 2000.f); // ----- - BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); - - CGFloat buttonSide = (isPortrait ? 64.f : 44.f); - CGFloat inset = (isPortrait ? 3.f : 2.f); - CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f); - CGFloat plusButtonFontSize = buttonsFontSize*1.5; - - _plusButtonsView.buttonInset = UIEdgeInsetsMake(inset, inset, inset, inset); - _plusButtonsView.contentInset = UIEdgeInsetsMake(inset, inset, inset, inset); - [_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]]; + _exampleView.frame = CGRectMake(0.f, 0.f, _scrollView.frame.size.width, 400.f); +} - _plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize]; - _plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1); +#pragma mark - - _plusButtonsView.buttonsSize = CGSizeMake(buttonSide, buttonSide); +- (void)showHideButtonsAction +{ + if (_plusButtonsViewNavBar.isShowing) + [_plusButtonsViewNavBar hideAnimated:YES completionHandler:nil]; + else + [_plusButtonsViewNavBar showAnimated:YES completionHandler:nil]; } + @end diff --git a/Demo/LGPlusButtonsViewDemo/PlusViewController.h b/Demo/LGPlusButtonsViewDemo/PlusViewController.h deleted file mode 100644 index 39c074d..0000000 --- a/Demo/LGPlusButtonsViewDemo/PlusViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// PlusViewController.h -// LGPlusButtonsViewDemo -// -// Created by Grigory Lutkov on 05.03.15. -// Copyright (c) 2015 Grigory Lutkov. All rights reserved. -// - -#import - -@interface PlusViewController : UIViewController - -- (id)initWithTitle:(NSString *)title; - -@end diff --git a/Demo/LGPlusButtonsViewDemo/PlusViewController.m b/Demo/LGPlusButtonsViewDemo/PlusViewController.m deleted file mode 100644 index 0fd1c75..0000000 --- a/Demo/LGPlusButtonsViewDemo/PlusViewController.m +++ /dev/null @@ -1,116 +0,0 @@ -// -// PlusViewController.m -// LGPlusButtonsViewDemo -// -// Created by Grigory Lutkov on 05.03.15. -// Copyright (c) 2015 Grigory Lutkov. All rights reserved. -// - -#import "PlusViewController.h" -#import "LGPlusButtonsView.h" - -@interface PlusViewController () - -@property (strong, nonatomic) UIView *contentView; -@property (strong, nonatomic) UILabel *textLabel; -@property (strong, nonatomic) LGPlusButtonsView *plusButtonsView; - -@end - -@implementation PlusViewController - -- (id)initWithTitle:(NSString *)title -{ - self = [super init]; - if (self) - { - self.title = title; - - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showHideButtonsAction)]; - - // ----- - - _contentView = [UIView new]; - _contentView.backgroundColor = [UIColor whiteColor]; - [self.view addSubview:_contentView]; - - _textLabel = [UILabel new]; - _textLabel.backgroundColor = [UIColor clearColor]; - _textLabel.text = @"UIView"; - [_contentView addSubview:_textLabel]; - - _plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_contentView - numberOfButtons:3 - showsPlusButton:NO - actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) - { - NSLog(@"%@, %@, %i", title, description, (int)index); - } - plusButtonActionHandler:nil]; - - [_plusButtonsView setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal]; - [_plusButtonsView setDescriptionsTexts:@[@"Button One description", @"Button Two description", @"Button Three description"]]; - _plusButtonsView.position = LGPlusButtonsViewPositionTopRight; - _plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop; - [_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO]; - [_plusButtonsView setButtonsImage:[UIImage imageNamed:@"Circle_Normal"] forState:UIControlStateNormal]; - [_plusButtonsView setButtonsImage:[UIImage imageNamed:@"Circle_Highlighted"] forState:UIControlStateHighlighted]; - [_plusButtonsView setButtonsLayerShadowColor:[UIColor blackColor] shadowOpacity:0.5 shadowOffset:CGSizeZero shadowRadius:2.f]; - } - return self; -} - -- (void)showHideButtonsAction -{ - if (_plusButtonsView.isShowing) - [_plusButtonsView hideAnimated:YES completionHandler:nil]; - else - [_plusButtonsView showAnimated:YES completionHandler:nil]; -} - -#pragma mark - Dealloc - -- (void)dealloc -{ - NSLog(@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__); -} - -#pragma mark - Appearing - -- (void)viewWillLayoutSubviews -{ - [super viewWillLayoutSubviews]; - - CGFloat topInset = 0.f; - if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) - { - topInset += (self.navigationController.navigationBarHidden ? 0.f : MIN(self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)); - topInset += ([UIApplication sharedApplication].statusBarHidden ? 0.f : MIN([UIApplication sharedApplication].statusBarFrame.size.width, [UIApplication sharedApplication].statusBarFrame.size.height)); - } - _contentView.frame = CGRectMake(0.f, topInset, self.view.frame.size.width, self.view.frame.size.height-topInset); - - [_textLabel sizeToFit]; - _textLabel.center = CGPointMake(_contentView.frame.size.width/2, _contentView.frame.size.height-20.f-_textLabel.frame.size.height/2); - _textLabel.frame = CGRectIntegral(_textLabel.frame); - - // ----- - - BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); - - CGFloat buttonSide = (isPortrait ? 64.f : 44.f); - CGFloat inset = (isPortrait ? 3.f : 2.f); - CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f); - CGFloat plusButtonFontSize = buttonsFontSize*1.5; - - _plusButtonsView.buttonInset = UIEdgeInsetsMake(inset, inset, inset, inset); - _plusButtonsView.contentInset = UIEdgeInsetsMake(inset, inset, inset, inset); - [_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]]; - - _plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize]; - _plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1); - - _plusButtonsView.buttonsSize = CGSizeMake(buttonSide, buttonSide); -} - -@end diff --git a/Demo/LGPlusButtonsViewDemo/TableViewController.h b/Demo/LGPlusButtonsViewDemo/TableViewController.h deleted file mode 100644 index fe8505a..0000000 --- a/Demo/LGPlusButtonsViewDemo/TableViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// TableViewController.h -// LGPlusButtonsViewDemo -// -// Created by Grigory Lutkov on 26.02.15. -// Copyright (c) 2015 Grigory Lutkov. All rights reserved. -// - -#import - -@interface TableViewController : UITableViewController - -@end diff --git a/Demo/LGPlusButtonsViewDemo/TableViewController.m b/Demo/LGPlusButtonsViewDemo/TableViewController.m deleted file mode 100644 index 140b62d..0000000 --- a/Demo/LGPlusButtonsViewDemo/TableViewController.m +++ /dev/null @@ -1,81 +0,0 @@ -// -// TableViewController.m -// LGPlusButtonsViewDemo -// -// Created by Grigory Lutkov on 26.02.15. -// Copyright (c) 2015 Grigory Lutkov. All rights reserved. -// - -#import "TableViewController.h" -#import "PlusViewController.h" -#import "PlusScrollViewController.h" - -@interface TableViewController () - -@property (strong, nonatomic) NSArray *titlesArray; - -@end - -@implementation TableViewController - -- (id)init -{ - self = [super initWithStyle:UITableViewStylePlain]; - if (self) - { - self.title = @"LGPlusButtonsView"; - - _titlesArray = @[@"UIView", - @"UIScrollView"]; - - [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; - - self.clearsSelectionOnViewWillAppear = YES; - } - return self; -} - -#pragma mark - UITableView DataSource - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return 1; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return _titlesArray.count; -} - -#pragma mark - UITableView Delegate - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; - - cell.textLabel.font = [UIFont systemFontOfSize:16.f]; - cell.textLabel.text = _titlesArray[indexPath.row]; - - return cell; -} - -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return 44.f; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (indexPath.row == 0) - { - PlusViewController *viewController = [[PlusViewController alloc] initWithTitle:_titlesArray[indexPath.row]]; - [self.navigationController pushViewController:viewController animated:YES]; - } - else if (indexPath.row == 1) - { - PlusScrollViewController *viewController = [[PlusScrollViewController alloc] initWithTitle:_titlesArray[indexPath.row]]; - [self.navigationController pushViewController:viewController animated:YES]; - } -} - -@end diff --git a/Framework/LGPlusButtonsViewFramework.xcodeproj/project.pbxproj b/Framework/LGPlusButtonsViewFramework.xcodeproj/project.pbxproj index b446121..602ef93 100644 --- a/Framework/LGPlusButtonsViewFramework.xcodeproj/project.pbxproj +++ b/Framework/LGPlusButtonsViewFramework.xcodeproj/project.pbxproj @@ -7,14 +7,22 @@ objects = { /* Begin PBXBuildFile section */ + 4AA8A3041C0B5D3F005EAE92 /* LGPlusButtonDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AA8A3001C0B5D3F005EAE92 /* LGPlusButtonDescription.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 4AA8A3051C0B5D40005EAE92 /* LGPlusButtonDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AA8A3011C0B5D3F005EAE92 /* LGPlusButtonDescription.m */; }; + 4AA8A3061C0B5D40005EAE92 /* LGPlusButtonsViewShared.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AA8A3021C0B5D3F005EAE92 /* LGPlusButtonsViewShared.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 4AA8A3071C0B5D40005EAE92 /* LGPlusButtonsViewShared.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AA8A3031C0B5D3F005EAE92 /* LGPlusButtonsViewShared.m */; }; 4AF139701BF384800037B073 /* LGPlusButtonsViewFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AF1396F1BF384800037B073 /* LGPlusButtonsViewFramework.h */; }; - 4AF13A261BF3B0E10037B073 /* LGPlusButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AF13A221BF3B0E10037B073 /* LGPlusButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4AF13A261BF3B0E10037B073 /* LGPlusButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AF13A221BF3B0E10037B073 /* LGPlusButton.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4AF13A271BF3B0E10037B073 /* LGPlusButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AF13A231BF3B0E10037B073 /* LGPlusButton.m */; }; 4AF13A281BF3B0E10037B073 /* LGPlusButtonsView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AF13A241BF3B0E10037B073 /* LGPlusButtonsView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4AF13A291BF3B0E10037B073 /* LGPlusButtonsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AF13A251BF3B0E10037B073 /* LGPlusButtonsView.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4AA8A3001C0B5D3F005EAE92 /* LGPlusButtonDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonDescription.h; sourceTree = ""; }; + 4AA8A3011C0B5D3F005EAE92 /* LGPlusButtonDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButtonDescription.m; sourceTree = ""; }; + 4AA8A3021C0B5D3F005EAE92 /* LGPlusButtonsViewShared.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonsViewShared.h; sourceTree = ""; }; + 4AA8A3031C0B5D3F005EAE92 /* LGPlusButtonsViewShared.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGPlusButtonsViewShared.m; sourceTree = ""; }; 4AF1396C1BF384800037B073 /* LGPlusButtonsViewFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LGPlusButtonsViewFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4AF1396F1BF384800037B073 /* LGPlusButtonsViewFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LGPlusButtonsViewFramework.h; sourceTree = ""; }; 4AF139711BF384800037B073 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -68,6 +76,10 @@ 4AF13A231BF3B0E10037B073 /* LGPlusButton.m */, 4AF13A241BF3B0E10037B073 /* LGPlusButtonsView.h */, 4AF13A251BF3B0E10037B073 /* LGPlusButtonsView.m */, + 4AA8A3001C0B5D3F005EAE92 /* LGPlusButtonDescription.h */, + 4AA8A3011C0B5D3F005EAE92 /* LGPlusButtonDescription.m */, + 4AA8A3021C0B5D3F005EAE92 /* LGPlusButtonsViewShared.h */, + 4AA8A3031C0B5D3F005EAE92 /* LGPlusButtonsViewShared.m */, ); name = LGPlusButtonsView; path = ../LGPlusButtonsView; @@ -81,7 +93,9 @@ buildActionMask = 2147483647; files = ( 4AF13A281BF3B0E10037B073 /* LGPlusButtonsView.h in Headers */, + 4AA8A3061C0B5D40005EAE92 /* LGPlusButtonsViewShared.h in Headers */, 4AF13A261BF3B0E10037B073 /* LGPlusButton.h in Headers */, + 4AA8A3041C0B5D3F005EAE92 /* LGPlusButtonDescription.h in Headers */, 4AF139701BF384800037B073 /* LGPlusButtonsViewFramework.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -153,8 +167,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4AA8A3071C0B5D40005EAE92 /* LGPlusButtonsViewShared.m in Sources */, 4AF13A271BF3B0E10037B073 /* LGPlusButton.m in Sources */, 4AF13A291BF3B0E10037B073 /* LGPlusButtonsView.m in Sources */, + 4AA8A3051C0B5D40005EAE92 /* LGPlusButtonDescription.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Framework/LGPlusButtonsViewFramework/LGPlusButtonsViewFramework.h b/Framework/LGPlusButtonsViewFramework/LGPlusButtonsViewFramework.h index a246a75..add890e 100644 --- a/Framework/LGPlusButtonsViewFramework/LGPlusButtonsViewFramework.h +++ b/Framework/LGPlusButtonsViewFramework/LGPlusButtonsViewFramework.h @@ -18,3 +18,5 @@ FOUNDATION_EXPORT const unsigned char LGPlusButtonsViewFrameworkVersionString[]; #import #import +#import +#import diff --git a/LGPlusButtonsView.podspec b/LGPlusButtonsView.podspec index 17f8b62..ffe565e 100644 --- a/LGPlusButtonsView.podspec +++ b/LGPlusButtonsView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LGPlusButtonsView' - s.version = '1.0.7' + s.version = '1.1.0' s.platform = :ios, '6.0' s.license = 'MIT' s.homepage = 'https://github.com/Friend-LGA/LGPlusButtonsView' diff --git a/LGPlusButtonsView/LGPlusButton.h b/LGPlusButtonsView/LGPlusButton.h index 039d22e..c36e035 100644 --- a/LGPlusButtonsView/LGPlusButton.h +++ b/LGPlusButtonsView/LGPlusButton.h @@ -28,13 +28,43 @@ // #import +#import "LGPlusButtonsView.h" @interface LGPlusButton : UIButton -@property (assign, nonatomic) CGPoint titleOffset; -@property (assign, nonatomic) CGPoint imageOffset; +@property (assign, nonatomic, getter=isShowing) BOOL showing; + +- (void)updateParametersForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setImage:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIImage *)imageForState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setTitleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIFont *)titleFontForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIEdgeInsets)insetsForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGPoint)offsetForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGSize)sizeForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setTitleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGPoint)titleOffsetForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setImageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGPoint)imageOffsetForOrientation:(LGPlusButtonsViewOrientation)orientation; - (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; +- (UIColor *)backgroundColorForState:(UIControlState)state; + +- (void)setLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGFloat)layerCornerRadiusForOrientation:(LGPlusButtonsViewOrientation)orientation; /** Unavailable, use titleOffset and imageOffset instead */ - (void)setContentHorizontalAlignment:(UIControlContentHorizontalAlignment)contentHorizontalAlignment __attribute__((unavailable("Use titleOffset and imageOffset instead"))); diff --git a/LGPlusButtonsView/LGPlusButton.m b/LGPlusButtonsView/LGPlusButton.m index 5bca8aa..fb38595 100644 --- a/LGPlusButtonsView/LGPlusButton.m +++ b/LGPlusButtonsView/LGPlusButton.m @@ -28,11 +28,25 @@ // #import "LGPlusButton.h" +#import "LGPlusButtonsViewShared.h" -// Do not forget about "protected" @interface LGPlusButton () -@property (assign, nonatomic, getter=isShowing) BOOL showing; +@property (strong, nonatomic) NSMutableDictionary *imagesDictionary; +@property (strong, nonatomic) NSMutableDictionary *titleFontsDictionary; +@property (strong, nonatomic) NSMutableDictionary *insetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *offsetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *sizesDictionary; +@property (strong, nonatomic) NSMutableDictionary *contentEdgeInsetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *titleOffsetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *imageOffsetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *backgroundColorsDictionary; +@property (strong, nonatomic) NSMutableDictionary *layerCornerRadiusDictionary; + +@property (assign, nonatomic) UIEdgeInsets insets; +@property (assign, nonatomic) CGSize size; +@property (assign, nonatomic) CGPoint titleOffset; +@property (assign, nonatomic) CGPoint imageOffset; @end @@ -45,11 +59,25 @@ - (instancetype)init { self.backgroundColor = [UIColor clearColor]; self.layer.anchorPoint = CGPointMake(0.5, 0.5); - - self.imageView.contentMode = UIViewContentModeScaleAspectFit; - - _titleOffset = CGPointZero; - _imageOffset = CGPointZero; + self.layer.masksToBounds = YES; + self.imageView.contentMode = UIViewContentModeCenter; + + // ----- + + _imagesDictionary = [NSMutableDictionary new]; + _titleFontsDictionary = [NSMutableDictionary new]; + _insetsDictionary = [NSMutableDictionary new]; + _offsetsDictionary = [NSMutableDictionary new]; + _sizesDictionary = [NSMutableDictionary new]; + _contentEdgeInsetsDictionary = [NSMutableDictionary new]; + _titleOffsetsDictionary = [NSMutableDictionary new]; + _imageOffsetsDictionary = [NSMutableDictionary new]; + _backgroundColorsDictionary = [NSMutableDictionary new]; + _layerCornerRadiusDictionary = [NSMutableDictionary new]; + + // ----- + + [self setInsets:UIEdgeInsetsMake(kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin) forOrientation:LGPlusButtonsViewOrientationAll]; } return self; } @@ -59,14 +87,22 @@ - (instancetype)init - (void)layoutSubviews { [super layoutSubviews]; - + + // ----- + + LGPlusButtonsViewOrientation orientation = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationLandscape; + + // ----- + CGFloat scaleX = [[self.layer valueForKeyPath:@"transform.scale.x"] floatValue]; CGFloat scaleY = [[self.layer valueForKeyPath:@"transform.scale.y"] floatValue]; CGRect selfFrame = CGRectMake(0.f, 0.f, self.frame.size.width/scaleX, self.frame.size.height/scaleY); - - CGSize sizeToFit = CGSizeMake(selfFrame.size.width-self.contentEdgeInsets.left-self.contentEdgeInsets.right, - selfFrame.size.height-self.contentEdgeInsets.top-self.contentEdgeInsets.bottom); + + UIEdgeInsets contentEdgeInsets = [self contentEdgeInsetsForOrientation:orientation]; + + CGSize sizeToFit = CGSizeMake(selfFrame.size.width-contentEdgeInsets.left-contentEdgeInsets.right, + selfFrame.size.height-contentEdgeInsets.top-contentEdgeInsets.bottom); if (self.titleLabel.text.length) { @@ -75,7 +111,8 @@ - (void)layoutSubviews selfFrame.size.height/2-titleLabelSize.height/2+_titleOffset.y, titleLabelSize.width, titleLabelSize.height); - if ([UIScreen mainScreen].scale == 1.f) titleLabelFrame = CGRectIntegral(titleLabelFrame); + if ([UIScreen mainScreen].scale == 1.f) + titleLabelFrame = CGRectIntegral(titleLabelFrame); self.titleLabel.frame = titleLabelFrame; } @@ -94,66 +131,254 @@ - (void)layoutSubviews selfFrame.size.height/2-imageViewSize.height/2+_imageOffset.y, imageViewSize.width, imageViewSize.height); - if ([UIScreen mainScreen].scale == 1.f) imageViewFrame = CGRectIntegral(imageViewFrame); + if ([UIScreen mainScreen].scale == 1.f) + imageViewFrame = CGRectIntegral(imageViewFrame); self.imageView.frame = imageViewFrame; } } - (CGSize)sizeThatFits:(CGSize)size { + LGPlusButtonsViewOrientation orientation = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationLandscape; + + // ----- + + CGSize buttonSize = [self sizeForOrientation:orientation]; + if (!CGSizeEqualToSize(buttonSize, CGSizeZero)) + return buttonSize; + + UIEdgeInsets contentEdgeInsets = [self contentEdgeInsetsForOrientation:orientation]; + CGSize titleLabelSize = (self.titleLabel.text.length ? [self.titleLabel sizeThatFits:size] : CGSizeZero); CGSize imageViewSize = (self.imageView.image ? [self.imageView sizeThatFits:size] : CGSizeZero); - - CGSize resultSize = CGSizeMake(MAX(titleLabelSize.width, imageViewSize.width)+self.contentEdgeInsets.left+self.contentEdgeInsets.right, - MAX(titleLabelSize.height, imageViewSize.height)+self.contentEdgeInsets.top+self.contentEdgeInsets.bottom); - + + CGSize resultSize = CGSizeMake(MAX(titleLabelSize.width, imageViewSize.width)+contentEdgeInsets.left+contentEdgeInsets.right, + MAX(titleLabelSize.height, imageViewSize.height)+contentEdgeInsets.top+contentEdgeInsets.bottom); + return resultSize; } #pragma mark - Setters and Getters -- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state +- (void)updateParametersForOrientation:(LGPlusButtonsViewOrientation)orientation { - [self setBackgroundImage:[LGPlusButton image1x1WithColor:backgroundColor] forState:state]; + [self setImage:[self imageForState:UIControlStateNormal forOrientation:orientation] forState:UIControlStateNormal]; + [self setImage:[self imageForState:UIControlStateHighlighted forOrientation:orientation] forState:UIControlStateHighlighted]; + [self setImage:[self imageForState:UIControlStateSelected forOrientation:orientation] forState:UIControlStateSelected]; + [self setImage:[self imageForState:UIControlStateDisabled forOrientation:orientation] forState:UIControlStateDisabled]; + [self setImage:[self imageForState:UIControlStateHighlighted|UIControlStateSelected forOrientation:orientation] forState:UIControlStateHighlighted|UIControlStateSelected]; + [self setImage:[self imageForState:UIControlStateHighlighted|UIControlStateDisabled forOrientation:orientation] forState:UIControlStateHighlighted|UIControlStateDisabled]; + [self setImage:[self imageForState:UIControlStateSelected|UIControlStateDisabled forOrientation:orientation] forState:UIControlStateSelected|UIControlStateDisabled]; + + self.titleLabel.font = [self titleFontForOrientation:orientation]; + self.contentEdgeInsets = [self contentEdgeInsetsForOrientation:orientation]; + self.insets = [self insetsForOrientation:orientation]; + self.size = [self sizeForOrientation:orientation]; + self.titleOffset = [self titleOffsetForOrientation:orientation]; + self.imageOffset = [self imageOffsetForOrientation:orientation]; + self.layer.cornerRadius = [self layerCornerRadiusForOrientation:orientation]; } -- (void)setTitleOffset:(CGPoint)titleOffset +- (void)setImage:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation { - if (!CGPointEqualToPoint(_titleOffset, titleOffset)) + [_imagesDictionary setObject:image forKey:[LGPlusButtonsViewShared stringFromState:state andOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) { - _titleOffset = titleOffset; - - [self layoutSubviews]; + [_imagesDictionary setObject:image forKey:[LGPlusButtonsViewShared stringFromState:state andOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_imagesDictionary setObject:image forKey:[LGPlusButtonsViewShared stringFromState:state andOrientation:LGPlusButtonsViewOrientationLandscape]]; } + + [self setNeedsLayout]; +} + +- (UIImage *)imageForState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + return [_imagesDictionary objectForKey:[LGPlusButtonsViewShared stringFromState:state andOrientation:orientation]]; } -- (void)setImageOffset:(CGPoint)imageOffset +- (void)setTitleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation { - if (!CGPointEqualToPoint(_imageOffset, imageOffset)) + [_titleFontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) { - _imageOffset = imageOffset; - - [self layoutSubviews]; + [_titleFontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_titleFontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; } + + [self setNeedsLayout]; } -#pragma mark - Support +- (UIFont *)titleFontForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + return [_titleFontsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; +} -+ (UIImage *)image1x1WithColor:(UIColor *)color +- (void)setInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation { - CGRect rect = CGRectMake(0.f, 0.f, 1.f, 1.f); - - UIGraphicsBeginImageContext(rect.size); - - CGContextRef context = UIGraphicsGetCurrentContext(); - - CGContextSetFillColorWithColor(context, color.CGColor); - CGContextFillRect(context, rect); - - UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return image; + NSString *insetsString = NSStringFromUIEdgeInsets(insets); + + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (UIEdgeInsets)insetsForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *insetsString = [_insetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (insetsString ? UIEdgeInsetsFromString(insetsString) : UIEdgeInsetsZero); +} + +- (void)setOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *offsetString = NSStringFromCGPoint(offset); + + [_offsetsDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_offsetsDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_offsetsDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGPoint)offsetForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *offsetString = [_offsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (offsetString ? CGPointFromString(offsetString) : CGPointZero); +} + +- (void)setSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *sizeString = NSStringFromCGSize(size); + + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGSize)sizeForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *sizeString = [_sizesDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (sizeString ? CGSizeFromString(sizeString) : CGSizeZero); +} + +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *contentEdgeInsetsString = NSStringFromUIEdgeInsets(contentEdgeInsets); + + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *contentEdgeInsetsString = [_contentEdgeInsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (contentEdgeInsetsString ? UIEdgeInsetsFromString(contentEdgeInsetsString) : UIEdgeInsetsZero); +} + +- (void)setTitleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *titleOffsetString = NSStringFromCGPoint(titleOffset); + + [_titleOffsetsDictionary setObject:titleOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_titleOffsetsDictionary setObject:titleOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_titleOffsetsDictionary setObject:titleOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGPoint)titleOffsetForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *titleOffsetString = [_titleOffsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (titleOffsetString ? CGPointFromString(titleOffsetString) : CGPointZero); +} + +- (void)setImageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *imageOffsetString = NSStringFromCGPoint(imageOffset); + + [_imageOffsetsDictionary setObject:imageOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_imageOffsetsDictionary setObject:imageOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_imageOffsetsDictionary setObject:imageOffsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGPoint)imageOffsetForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *imageOffsetString = [_imageOffsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (imageOffsetString ? CGPointFromString(imageOffsetString) : CGPointZero); +} + +- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state +{ + [self setBackgroundImage:[LGPlusButtonsViewShared image1x1WithColor:backgroundColor] forState:state]; + + [_backgroundColorsDictionary setObject:backgroundColor forKey:[LGPlusButtonsViewShared stringFromState:state]]; +} + +- (UIColor *)backgroundColorForState:(UIControlState)state +{ + return [_backgroundColorsDictionary objectForKey:[LGPlusButtonsViewShared stringFromState:state]]; +} + +- (void)setLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSNumber *cornerRadiusNumber = [NSNumber numberWithFloat:cornerRadius]; + + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGFloat)layerCornerRadiusForOrientation:(LGPlusButtonsViewOrientation)orientation; +{ + NSNumber *cornerRadiusNumber = [_layerCornerRadiusDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (cornerRadiusNumber ? cornerRadiusNumber.floatValue : 0.f); } @end diff --git a/LGPlusButtonsView/LGPlusButtonDescription.h b/LGPlusButtonsView/LGPlusButtonDescription.h new file mode 100644 index 0000000..dd83afb --- /dev/null +++ b/LGPlusButtonsView/LGPlusButtonDescription.h @@ -0,0 +1,55 @@ +// +// LGPlusButtonDescription.h +// LGPlusButtonsView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGPlusButtonsView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import +#import "LGPlusButtonsView.h" + +@interface LGPlusButtonDescription : UILabel + +- (void)updateParametersForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIFont *)fontForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIEdgeInsets)insetsForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGPoint)offsetForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGSize)sizeForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (CGFloat)layerCornerRadiusForOrientation:(LGPlusButtonsViewOrientation)orientation; + +@end diff --git a/LGPlusButtonsView/LGPlusButtonDescription.m b/LGPlusButtonsView/LGPlusButtonDescription.m new file mode 100644 index 0000000..fc6cefc --- /dev/null +++ b/LGPlusButtonsView/LGPlusButtonDescription.m @@ -0,0 +1,249 @@ +// +// LGPlusButtonDescription.m +// LGPlusButtonsView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGPlusButtonsView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import "LGPlusButtonDescription.h" +#import "LGPlusButtonsViewShared.h" + +@interface LGPlusButtonDescription () + +@property (strong, nonatomic) NSMutableDictionary *fontsDictionary; +@property (strong, nonatomic) NSMutableDictionary *insetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *offsetDictionary; +@property (strong, nonatomic) NSMutableDictionary *sizesDictionary; +@property (strong, nonatomic) NSMutableDictionary *contentEdgeInsetsDictionary; +@property (strong, nonatomic) NSMutableDictionary *layerCornerRadiusDictionary; + +@property (assign, nonatomic) UIEdgeInsets contentEdgeInsets; +@property (assign, nonatomic) UIEdgeInsets insets; +@property (assign, nonatomic) CGSize size; + +@end + +@implementation LGPlusButtonDescription + +- (instancetype)init +{ + self = [super init]; + if (self) + { + self.numberOfLines = 0; + self.backgroundColor = [UIColor clearColor]; + self.layer.masksToBounds = YES; + self.userInteractionEnabled = NO; + + // ----- + + _fontsDictionary = [NSMutableDictionary new]; + _insetsDictionary = [NSMutableDictionary new]; + _offsetDictionary = [NSMutableDictionary new]; + _sizesDictionary = [NSMutableDictionary new]; + _contentEdgeInsetsDictionary = [NSMutableDictionary new]; + _layerCornerRadiusDictionary = [NSMutableDictionary new]; + + // ----- + + [self setFont:[UIFont systemFontOfSize:14.f] forOrientation:LGPlusButtonsViewOrientationAll]; + [self setInsets:UIEdgeInsetsMake(kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin) forOrientation:LGPlusButtonsViewOrientationAll]; + } + return self; +} + +#pragma mark - + +- (void)drawTextInRect:(CGRect)rect +{ + rect.origin.x += _contentEdgeInsets.left; + rect.size.width -= (_contentEdgeInsets.left+_contentEdgeInsets.right); + + [super drawTextInRect:rect]; +} + +- (CGSize)sizeThatFits:(CGSize)size +{ + LGPlusButtonsViewOrientation orientation = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationLandscape; + + // ----- + + CGSize descriptionSize = [self sizeForOrientation:orientation]; + if (!CGSizeEqualToSize(descriptionSize, CGSizeZero)) + return descriptionSize; + + size.width -= (_insets.left+_insets.right+_contentEdgeInsets.left+_contentEdgeInsets.right); + + CGSize resultSize = (self.text.length ? [super sizeThatFits:size] : CGSizeZero); + + if (!CGSizeEqualToSize(resultSize, CGSizeZero)) + { + resultSize.width += _contentEdgeInsets.left+_contentEdgeInsets.right; + resultSize.height += _contentEdgeInsets.top+_contentEdgeInsets.bottom; + } + + return resultSize; +} + +#pragma mark - Setters and Getters + +- (void)updateParametersForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + self.font = [self fontForOrientation:orientation]; + self.contentEdgeInsets = [self contentEdgeInsetsForOrientation:orientation]; + self.insets = [self insetsForOrientation:orientation]; + self.size = [self sizeForOrientation:orientation]; + self.layer.cornerRadius = [self layerCornerRadiusForOrientation:orientation]; +} + +- (void)setFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + [_fontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_fontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_fontsDictionary setObject:font forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (UIFont *)fontForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + return [_fontsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; +} + +- (void)setInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *insetsString = NSStringFromUIEdgeInsets(insets); + + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_insetsDictionary setObject:insetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (UIEdgeInsets)insetsForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *insetsString = [_insetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (insetsString ? UIEdgeInsetsFromString(insetsString) : UIEdgeInsetsZero); +} + +- (void)setOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *offsetString = NSStringFromCGPoint(offset); + + [_offsetDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_offsetDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_offsetDictionary setObject:offsetString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGPoint)offsetForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *offsetString = [_offsetDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (offsetString ? CGPointFromString(offsetString) : CGPointZero); +} + +- (void)setSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *sizeString = NSStringFromCGSize(size); + + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_sizesDictionary setObject:sizeString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGSize)sizeForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *sizeString = [_sizesDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (sizeString ? CGSizeFromString(sizeString) : CGSizeZero); +} + +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *contentEdgeInsetsString = NSStringFromUIEdgeInsets(contentEdgeInsets); + + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSString *contentEdgeInsetsString = [_contentEdgeInsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (contentEdgeInsetsString ? UIEdgeInsetsFromString(contentEdgeInsetsString) : UIEdgeInsetsZero); +} + +- (void)setLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSNumber *cornerRadiusNumber = [NSNumber numberWithFloat:cornerRadius]; + + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) + { + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_layerCornerRadiusDictionary setObject:cornerRadiusNumber forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; + } + + [self setNeedsLayout]; +} + +- (CGFloat)layerCornerRadiusForOrientation:(LGPlusButtonsViewOrientation)orientation; +{ + NSNumber *cornerRadiusNumber = [_layerCornerRadiusDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (cornerRadiusNumber ? cornerRadiusNumber.floatValue : 0.f); +} + +@end diff --git a/LGPlusButtonsView/LGPlusButtonsView.h b/LGPlusButtonsView/LGPlusButtonsView.h index d229d0e..61521c6 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.h +++ b/LGPlusButtonsView/LGPlusButtonsView.h @@ -28,27 +28,55 @@ // #import -#import "LGPlusButton.h" @class LGPlusButtonsView; +static NSString *const kLGPlusButtonsViewWillShowNotification = @"kLGPlusButtonsViewWillShowNotification"; +static NSString *const kLGPlusButtonsViewWillHideNotification = @"kLGPlusButtonsViewWillHideNotification"; +static NSString *const kLGPlusButtonsViewDidShowNotification = @"kLGPlusButtonsViewDidShowNotification"; +static NSString *const kLGPlusButtonsViewDidHideNotification = @"kLGPlusButtonsViewDidHideNotification"; +static NSString *const kLGPlusButtonsViewWillShowButtonsNotification = @"kLGPlusButtonsViewWillShowButtonsNotification"; +static NSString *const kLGPlusButtonsViewWillHideButtonsNotification = @"kLGPlusButtonsViewWillHideButtonsNotification"; +static NSString *const kLGPlusButtonsViewDidShowButtonsNotification = @"kLGPlusButtonsViewDidShowButtonsNotification"; +static NSString *const kLGPlusButtonsViewDidHideButtonsNotification = @"kLGPlusButtonsViewDidHideButtonsNotification"; +static NSString *const kLGPlusButtonsViewActionNotification = @"kLGPlusButtonsViewActionNotification"; + + @protocol LGPlusButtonsViewDelegate @optional +- (void)plusButtonsViewWillShow:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillHide:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidShow:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidHide:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillShowButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillHideButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidShowButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidHideButtons:(LGPlusButtonsView *)plusButtonsView; - (void)plusButtonsView:(LGPlusButtonsView *)plusButtonsView buttonPressedWithTitle:(NSString *)title description:(NSString *)description index:(NSUInteger)index; -- (void)plusButtonsViewPlusButtonPressed:(LGPlusButtonsView *)plusButtonsView; -- (BOOL)plusButtonsViewShouldHide:(LGPlusButtonsView *)plusButtonsView; + @end @interface LGPlusButtonsView : UIView +typedef NS_ENUM(NSUInteger, LGPlusButtonsViewOrientation) +{ + LGPlusButtonsViewOrientationAll = 0, + LGPlusButtonsViewOrientationPortrait = 1, + LGPlusButtonsViewOrientationLandscape = 2 +}; + typedef NS_ENUM(NSUInteger, LGPlusButtonsViewPosition) { LGPlusButtonsViewPositionBottomRight = 0, LGPlusButtonsViewPositionBottomLeft = 1, LGPlusButtonsViewPositionTopRight = 2, - LGPlusButtonsViewPositionTopLeft = 3 + LGPlusButtonsViewPositionTopLeft = 3, + LGPlusButtonsViewPositionRightBottom = LGPlusButtonsViewPositionBottomRight, + LGPlusButtonsViewPositionLeftBottom = LGPlusButtonsViewPositionBottomLeft, + LGPlusButtonsViewPositionRightTop = LGPlusButtonsViewPositionTopRight, + LGPlusButtonsViewPositionLeftTop = LGPlusButtonsViewPositionTopRight }; typedef NS_ENUM(NSUInteger, LGPlusButtonsAppearingAnimationType) @@ -68,110 +96,195 @@ typedef NS_ENUM(NSUInteger, LGPlusButtonAnimationType) }; @property (assign, nonatomic, readonly, getter=isShowing) BOOL showing; -@property (assign, nonatomic, getter=isAlwaysVisible) BOOL alwaysVisible; - -@property (strong, nonatomic) LGPlusButton *plusButton; - -/** First is plusButton */ -@property (strong, nonatomic) NSMutableArray *buttons; -/** First is plusButton description */ -@property (strong, nonatomic) NSMutableArray *descriptions; - -@property (assign, nonatomic) UIEdgeInsets contentInset; -@property (assign, nonatomic) UIEdgeInsets buttonInset; -@property (assign, nonatomic) CGSize buttonsSize; -@property (assign, nonatomic) CGSize plusButtonSize; -/** Description horizontal offset from button, default is 6.f */ -@property (assign, nonatomic) CGFloat descriptionOffsetX; -@property (assign, nonatomic) CGPoint offset; +@property (assign, nonatomic, readonly, getter=isButtonsShowing) BOOL buttonsShowing; +@property (assign, nonatomic, getter=isShowHideOnScroll) BOOL showHideOnScroll; +/** Hide additional buttons on scroll. Default is NO */ +@property (assign, nonatomic, getter=isHideButtonsOnScroll) BOOL hideButtonsOnScroll; +/** Default is YES */ +@property (assign, nonatomic, getter=isDisableShowHideOnScrollIfContentSizeLessThenFrame) BOOL disableShowHideOnScrollIfContentSizeLessThenFrame; +@property (assign, nonatomic) CGPoint offset; +@property (assign, nonatomic) LGPlusButtonsViewPosition position; +/** How much scroll you need to show/hide buttons. Default is 64.f */ +@property (assign, nonatomic) CGFloat scrollSensitivity; @property (assign, nonatomic) LGPlusButtonsAppearingAnimationType appearingAnimationType; @property (assign, nonatomic) LGPlusButtonsAppearingAnimationType buttonsAppearingAnimationType; @property (assign, nonatomic) LGPlusButtonAnimationType plusButtonAnimationType; -@property (assign, nonatomic) LGPlusButtonsViewPosition position; +@property (strong, nonatomic) UIColor *coverColor; -/** How much scroll you need to show/hide buttons. Default is 64.f */ -@property (assign, nonatomic) CGFloat scrollSensitivity; +/** Default is 0.3 */ +@property (assign, nonatomic) IBInspectable NSTimeInterval appearingAnimationSpeed; +/** Default is 0.3 */ +@property (assign, nonatomic) IBInspectable NSTimeInterval buttonsAppearingAnimationSpeed; -/** Hide additional buttons on scroll. Default is NO */ -@property (assign, nonatomic, getter=isHideButtonsOnScroll) BOOL hideButtonsOnScroll; +/** When user will interact with this scroll view, LGPlusButtonsView will show/hide */ +@property (assign, nonatomic) UIScrollView *observedScrollView; + +#pragma mark - Handlers /** Do not forget about weak referens to self */ -@property (strong, nonatomic) void (^actionHandler)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index); +@property (strong, nonatomic) void (^willShowHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^willHideHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^didShowHandler)(LGPlusButtonsView *plusButtonView); /** Do not forget about weak referens to self */ -@property (strong, nonatomic) void (^plusButtonActionHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^didHideHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^willShowButtonsHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^willHideButtonsHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^didShowButtonsHandler)(LGPlusButtonsView *plusButtonView); +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^didHideButtonsHandler)(LGPlusButtonsView *plusButtonView); + +/** Do not forget about weak referens to self */ +@property (strong, nonatomic) void (^actionHandler)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index); @property (assign, nonatomic) id delegate; -- (instancetype)initWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton; +/** Defailt is {4.f, 4.f, 4.f, 4.f} */ +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation; -+ (instancetype)plusButtonsViewWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton; +#pragma mark - Buttons all -#pragma mark - +- (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state; +- (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state; +- (void)setButtonsTitleColors:(NSArray *)titleColors forState:(UIControlState)state; +- (void)setButtonsBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state; +- (void)setButtonsBackgroundImages:(NSArray *)backgroundImages forState:(UIControlState)state; +- (void)setButtonsBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; +- (void)setButtonsBackgroundColors:(NSArray *)backgroundColors forState:(UIControlState)state; +- (void)setButtonsImage:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsImages:(NSArray *)images forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setButtonsTitleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +/** Defailt is {4.f, 4.f, 4.f, 4.f} */ +- (void)setButtonsInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsTitleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonsImageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; -/** Do not forget about weak referens to self for actionHandler and plusButtonActionHandler blocks */ -- (instancetype)initWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton - actionHandler:(void(^)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index))actionHandler - plusButtonActionHandler:(void(^)(LGPlusButtonsView *plusButtonView))plusButtonActionHandler; +- (void)setButtonsImageViewContentMode:(UIViewContentMode)contentMode; +- (void)setButtonsClipsToBounds:(BOOL)clipsToBounds; +- (void)setButtonsAdjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted; +- (void)setButtonsAdjustsImageWhenDisabled:(BOOL)adjustsImageWhenDisabled; +- (void)setButtonsEnabled:(BOOL)enabled; + +- (void)setButtonsLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation;; +- (void)setButtonsLayerBorderColor:(UIColor *)borderColor; +- (void)setButtonsLayerBorderWidth:(CGFloat)borderWidth; +- (void)setButtonsLayerShadowColor:(UIColor *)shadowColor; +- (void)setButtonsLayerShadowRadius:(CGFloat)shadowRadius; +- (void)setButtonsLayerShadowOpacity:(CGFloat)shadowOpacity; +- (void)setButtonsLayerShadowOffset:(CGSize)shadowOffset; + +#pragma mark - Button at index + +- (void)setButtonAtIndex:(NSUInteger)index title:(NSString *)title forState:(UIControlState)state; +- (void)setButtonAtIndex:(NSUInteger)index titleColor:(UIColor *)titleColor forState:(UIControlState)state; +- (void)setButtonAtIndex:(NSUInteger)index backgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state; +- (void)setButtonAtIndex:(NSUInteger)index backgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; +- (void)setButtonAtIndex:(NSUInteger)index image:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setButtonAtIndex:(NSUInteger)index titleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +/** Defailt is {4.f, 4.f, 4.f, 4.f} */ +- (void)setButtonAtIndex:(NSUInteger)index insets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonAtIndex:(NSUInteger)index offset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonAtIndex:(NSUInteger)index size:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonAtIndex:(NSUInteger)index contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonAtIndex:(NSUInteger)index titleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setButtonAtIndex:(NSUInteger)index imageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setButtonAtIndex:(NSUInteger)index imageViewContentMode:(UIViewContentMode)contentMode; +- (void)setButtonAtIndex:(NSUInteger)index clipsToBounds:(BOOL)clipsToBounds; +- (void)setButtonAtIndex:(NSUInteger)index adjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted; +- (void)setButtonAtIndex:(NSUInteger)index adjustsImageWhenDisabled:(BOOL)adjustsImageWhenDisabled; +- (void)setButtonAtIndex:(NSUInteger)index enabled:(BOOL)enabled; + +- (void)setButtonAtIndex:(NSUInteger)index layerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation;; +- (void)setButtonAtIndex:(NSUInteger)index layerBorderColor:(UIColor *)borderColor; +- (void)setButtonAtIndex:(NSUInteger)index layerBorderWidth:(CGFloat)borderWidth; + +#pragma mark - Descriptions all -/** Do not forget about weak referens to self for actionHandler and plusButtonActionHandler blocks */ -+ (instancetype)plusButtonsViewWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton - actionHandler:(void(^)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index))actionHandler - plusButtonActionHandler:(void(^)(LGPlusButtonsView *plusButtonView))plusButtonActionHandler; +- (void)setDescriptionsTexts:(NSArray *)texts; +- (void)setDescriptionsTextColor:(UIColor *)textColor; +- (void)setDescriptionsBackgroundColor:(UIColor *)backgroundColor; + +/** Defailt is [UIFont systemFontOfSize:14.f] */ +- (void)setDescriptionsFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +/** Defailt is {4.f, 4.f, 4.f, 4.f} */ +- (void)setDescriptionsInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionsOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionsSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setDescriptionsLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionsLayerBorderColor:(UIColor *)borderColor; +- (void)setDescriptionsLayerBorderWidth:(CGFloat)borderWidth; +- (void)setDescriptionsLayerShadowColor:(UIColor *)shadowColor; +- (void)setDescriptionsLayerShadowRadius:(CGFloat)shadowRadius; +- (void)setDescriptionsLayerShadowOpacity:(CGFloat)shadowOpacity; +- (void)setDescriptionsLayerShadowOffset:(CGSize)shadowOffset; + +#pragma mark - Description at index + +- (void)setDescriptionAtIndex:(NSUInteger)index text:(NSString *)text; +- (void)setDescriptionAtIndex:(NSUInteger)index textColor:(UIColor *)textColor; +- (void)setDescriptionAtIndex:(NSUInteger)index backgroundColor:(UIColor *)backgroundColor; + +/** Defailt is [UIFont systemFontOfSize:14.f] */ +- (void)setDescriptionAtIndex:(NSUInteger)index font:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation; +/** Defailt is {4.f, 4.f, 4.f, 4.f} */ +- (void)setDescriptionAtIndex:(NSUInteger)index insets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionAtIndex:(NSUInteger)index offset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionAtIndex:(NSUInteger)index size:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionAtIndex:(NSUInteger)index contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation; + +- (void)setDescriptionAtIndex:(NSUInteger)index layerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; +- (void)setDescriptionAtIndex:(NSUInteger)index layerBorderColor:(UIColor *)borderColor; +- (void)setDescriptionAtIndex:(NSUInteger)index layerBorderWidth:(CGFloat)borderWidth; #pragma mark - -- (instancetype)initWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton - delegate:(id)delegate; +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit; -+ (instancetype)plusButtonsViewWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton - delegate:(id)delegate; ++ (instancetype)plusButtonsViewWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit; #pragma mark - -- (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state; -- (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state; -- (void)setButtonsImage:(UIImage *)image forState:(UIControlState)state; -- (void)setButtonsImages:(NSArray *)images forState:(UIControlState)state; -- (void)setButtonsBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state; -- (void)setButtonsBackgroundImages:(NSArray *)backgroundImages forState:(UIControlState)state; -- (void)setButtonsBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; -- (void)setButtonsBackgroundColors:(NSArray *)backgroundColors forState:(UIControlState)state; -- (void)setButtonsTitleFont:(UIFont *)font; -- (void)setButtonsImageViewContentMode:(UIViewContentMode)contentMode; - -#pragma mark - +/** Do not forget about weak referens to self for actionHandler and plusButtonActionHandler blocks */ +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + actionHandler:(void(^)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index))actionHandler; -- (void)setDescriptionsTexts:(NSArray *)texts; -- (void)setDescriptionsTextColor:(UIColor *)textColor; -- (void)setDescriptionsBackgroundColor:(UIColor *)backgroundColor; -- (void)setDescriptionsFont:(UIFont *)font; +/** Do not forget about weak referens to self for actionHandler and plusButtonActionHandler blocks */ ++ (instancetype)plusButtonsViewWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + actionHandler:(void(^)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index))actionHandler; #pragma mark - -- (void)setButtonsClipsToBounds:(BOOL)clipsToBounds; -- (void)setButtonsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets; -- (void)setButtonsAdjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted; - -#pragma mark - +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + delegate:(id)delegate; -- (void)setButtonsLayerShouldRasterize:(BOOL)shouldRasterize; -- (void)setButtonsLayerMasksToBounds:(BOOL)masksToBounds; -- (void)setButtonsLayerCornerRadius:(CGFloat)cornerRadius; -- (void)setButtonsLayerBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth; -- (void)setButtonsLayerShadowColor:(UIColor *)shadowColor shadowOpacity:(float)shadowOpacity shadowOffset:(CGSize)shadowOffset shadowRadius:(CGFloat)shadowRadius; ++ (instancetype)plusButtonsViewWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + delegate:(id)delegate; #pragma mark - diff --git a/LGPlusButtonsView/LGPlusButtonsView.m b/LGPlusButtonsView/LGPlusButtonsView.m index 9ef6675..0e9a5b6 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.m +++ b/LGPlusButtonsView/LGPlusButtonsView.m @@ -28,8 +28,13 @@ // #import "LGPlusButtonsView.h" +#import "LGPlusButton.h" +#import "LGPlusButtonDescription.h" +#import "LGPlusButtonsViewShared.h" -#define kLGPlusButtonsViewDegreesToRadians(d) ((d) * M_PI / 180) +#define kLGPlusButtonsViewDegreesToRadians(d) ((d) * M_PI / 180) +#define kLGPlusButtonsViewAssertionWarning(value) [NSString stringWithFormat:@"Number of buttons needs to be equal to numbers of %@", value] +#define kLGPlusButtonsViewIndexAssertionWarning [NSString stringWithFormat:@"Index is out of buttons range"] @interface WrapperView : UIView @@ -41,26 +46,19 @@ @implementation WrapperView - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { - //NSLog(@"\nself = %@\nsuper = %@\nactionView = %@\nsubviews = %@\n\n", self, [super hitTest:point withEvent:event], _actionView, self.subviews); - - UIView *superView = [super hitTest:point withEvent:event]; - - UIView *view; - if (superView) - view = superView; - else if (_actionView) - view = _actionView; - - return view; -} + //NSLog(@"\nself = %@\nsuper = %@\nsubviews = %@\nsupersubviews = %@\n\n", self, [super hitTest:point withEvent:event], self.subviews, self.superview.subviews); -@end + UIView *view = nil; -#pragma mark - + if (_actionView) + { + CGPoint newPoint = [self convertPoint:point toView:_actionView]; -@interface LGPlusButton (protected) + view = [_actionView hitTest:newPoint withEvent:event]; + } -@property (assign, nonatomic, getter=isShowing) BOOL showing; + return view; +} @end @@ -68,95 +66,105 @@ @interface LGPlusButton (protected) @interface LGPlusButtonsView () -typedef enum +typedef NS_ENUM(NSUInteger, LGPlusButtonDescriptionsPosition) { - LGPlusButtondescriptionsPositionLeft = 0, - LGPlusButtondescriptionsPositionRight = 1 -} -LGPlusButtonDescriptionsPosition; + LGPlusButtonDescriptionsPositionLeft = 0, + LGPlusButtonDescriptionsPositionRight = 1 +}; @property (assign, nonatomic, getter=isObserversAdded) BOOL observersAdded; +@property (assign, nonatomic, getter=isObserversForScrollViewAdded) BOOL observersForScrollViewAdded; @property (assign, nonatomic) LGPlusButtonDescriptionsPosition descriptionsPosition; @property (assign, nonatomic) UIView *parentView; -@property (strong, nonatomic) NSMutableArray *buttonWrapperViews1; -@property (strong, nonatomic) NSMutableArray *buttonWrapperViews2; -@property (strong, nonatomic) NSMutableArray *descriptionWrapperViews; +@property (strong, nonatomic) WrapperView *contentView; +@property (strong, nonatomic) WrapperView *buttonsContentView; +@property (strong, nonatomic) UIView *descriptionsContentView; +@property (strong, nonatomic) UIView *coverView; -@property (strong, nonatomic) WrapperView *plusButtonWrapperView1; -@property (strong, nonatomic) WrapperView *plusButtonWrapperView2; -@property (strong, nonatomic) UILabel *plusDescription; -@property (strong, nonatomic) WrapperView *plusDescriptionWrapperView; +@property (strong, nonatomic) NSMutableArray *buttonsArray; +@property (strong, nonatomic) NSMutableArray *buttonWrapperViewsArray1; +@property (strong, nonatomic) NSMutableArray *buttonWrapperViewsArray2; + +@property (strong, nonatomic) NSMutableArray *descriptionsArray; +@property (strong, nonatomic) NSMutableArray *descriptionWrapperViewsArray; @property (assign, nonatomic) CGFloat offsetY; @property (assign, nonatomic) CGFloat tempOffsetY; @property (assign, nonatomic) CGFloat tempDiff; -@property (assign, nonatomic, getter=isShowsPlusButton) BOOL showsPlusButton; +@property (strong, nonatomic) NSMutableDictionary *contentEdgeInsetsDictionary; + +@property (assign, nonatomic, getter=isFirstButtonIsPlusButton) BOOL firstButtonIsPlusButton; + +@property (assign, nonatomic) NSTimeInterval hideAnimationCoef; @end @implementation LGPlusButtonsView -- (instancetype)initWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit { self = [super init]; if (self) { - _parentView = view; _appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical; _buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal; - _showsPlusButton = showsPlusButton; - _descriptionOffsetX = 6.f; + _firstButtonIsPlusButton = firstButtonIsPlusButton; _scrollSensitivity = 64.f; - + _appearingAnimationSpeed = 0.3; + _buttonsAppearingAnimationSpeed = 0.3; + _hideAnimationCoef = 0.66; + _showHideOnScroll = YES; + _disableShowHideOnScrollIfContentSizeLessThenFrame = YES; + // ----- - + + _contentEdgeInsetsDictionary = [NSMutableDictionary new]; + + [self setContentEdgeInsets:UIEdgeInsetsMake(kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin, kLGPlusButtonsViewMargin) + forOrientation:LGPlusButtonsViewOrientationAll]; + + // ----- + self.backgroundColor = [UIColor clearColor]; - self.hidden = YES; - + self.userInteractionEnabled = YES; + // ----- - - _buttonWrapperViews1 = [NSMutableArray new]; - _buttonWrapperViews2 = [NSMutableArray new]; - _buttons = [NSMutableArray new]; - - if (self.isShowsPlusButton) - { - _plusButtonWrapperView1 = [WrapperView new]; - _plusButtonWrapperView1.backgroundColor = [UIColor clearColor]; - _plusButtonWrapperView1.clipsToBounds = NO; - _plusButtonWrapperView1.layer.masksToBounds = NO; - _plusButtonWrapperView1.layer.anchorPoint = CGPointMake(0.5, 0.5); - _plusButtonWrapperView1.userInteractionEnabled = YES; - [self addSubview:_plusButtonWrapperView1]; - - [_buttonWrapperViews1 addObject:_plusButtonWrapperView1]; - - _plusButtonWrapperView2 = [WrapperView new]; - _plusButtonWrapperView2.backgroundColor = [UIColor clearColor]; - _plusButtonWrapperView2.clipsToBounds = NO; - _plusButtonWrapperView2.layer.masksToBounds = NO; - _plusButtonWrapperView2.layer.anchorPoint = CGPointMake(0.5, 0.5); - _plusButtonWrapperView2.userInteractionEnabled = YES; - [_plusButtonWrapperView1 addSubview:_plusButtonWrapperView2]; - - [_buttonWrapperViews2 addObject:_plusButtonWrapperView2]; - - _plusButton = [LGPlusButton new]; - [_plusButton addTarget:self action:@selector(plusButtonAction:) forControlEvents:UIControlEventTouchUpInside]; - [_plusButtonWrapperView2 addSubview:_plusButton]; - - _plusButtonWrapperView2.actionView = _plusButton; - [_buttons addObject:_plusButton]; - } - + + _coverView = [UIView new]; + _coverView.backgroundColor = [UIColor clearColor]; + _coverView.userInteractionEnabled = YES; + [self addSubview:_coverView]; + + _contentView = [WrapperView new]; + _contentView.backgroundColor = [UIColor clearColor]; + _contentView.userInteractionEnabled = YES; + [self addSubview:_contentView]; + + _buttonsContentView = [WrapperView new]; + _buttonsContentView.backgroundColor = [UIColor clearColor]; + _buttonsContentView.userInteractionEnabled = YES; + [_contentView addSubview:_buttonsContentView]; + + _descriptionsContentView = [UIView new]; + _descriptionsContentView.backgroundColor = [UIColor clearColor]; + _descriptionsContentView.userInteractionEnabled = NO; + [_contentView addSubview:_descriptionsContentView]; + + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; + [_coverView addGestureRecognizer:tapGesture]; + // ----- - + + _buttonWrapperViewsArray1 = [NSMutableArray new]; + _buttonWrapperViewsArray2 = [NSMutableArray new]; + _buttonsArray = [NSMutableArray new]; + for (NSUInteger i=0; i)delegate +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + delegate:(id)delegate { - self = [self initWithView:view numberOfButtons:numberOfButtons showsPlusButton:showsPlusButton]; + self = [self initWithNumberOfButtons:numberOfButtons + firstButtonIsPlusButton:firstButtonIsPlusButton + showAfterInit:showAfterInit]; if (self) { _delegate = delegate; @@ -309,15 +285,15 @@ - (instancetype)initWithView:(UIView *)view return self; } -+ (instancetype)plusButtonsViewWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton - delegate:(id)delegate ++ (instancetype)plusButtonsViewWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit + delegate:(id)delegate { - return [[self alloc] initWithView:view - numberOfButtons:numberOfButtons - showsPlusButton:showsPlusButton - delegate:delegate]; + return [[self alloc] initWithNumberOfButtons:numberOfButtons + firstButtonIsPlusButton:firstButtonIsPlusButton + showAfterInit:showAfterInit + delegate:delegate]; } #pragma mark - Dealloc @@ -331,656 +307,987 @@ - (void)dealloc #pragma mark - -- (void)willMoveToSuperview:(UIView *)newSuperview +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { - [super willMoveToSuperview:newSuperview]; + //NSLog(@"\nself = %@\nsuper = %@\nsubviews = %@\nsupersubviews = %@\n\n", self, [super hitTest:point withEvent:event], self.subviews, self.superview.subviews); - if (!newSuperview) - [self removeObservers]; - else - [self addObservers]; + UIView *view = nil; + + for (LGPlusButton *button in _buttonsArray) + { + CGPoint newPoint = [self convertPoint:point toView:button]; + + view = [button hitTest:newPoint withEvent:event]; + if (view) break; + } + + if (!view && _coverColor && !_coverView.isHidden) + { + CGPoint newPoint = [self convertPoint:point toView:_coverView]; + + view = [_coverView hitTest:newPoint withEvent:event]; + } + + return view; } --(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event { - id hitView = [super hitTest:point withEvent:event]; - if (hitView == self) { - return nil; - } else { - return hitView; - } +#pragma mark - + +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [self removeObservers:self.superview]; + + if (newSuperview) + [self addObservers:newSuperview]; + + [super willMoveToSuperview:newSuperview]; } #pragma mark - Setters and Getters -- (void)setAlwaysVisible:(BOOL)alwaysVisible +- (void)setCoverColor:(UIColor *)coverColor { - _alwaysVisible = alwaysVisible; + _coverColor = coverColor; - if (alwaysVisible) - [self showAnimated:NO completionHandler:nil]; + _coverView.backgroundColor = coverColor; } -- (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state +- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation { - BOOL isChanged = NO; - - for (NSUInteger i=0; i<_buttons.count; i++) + NSString *contentEdgeInsetsString = NSStringFromUIEdgeInsets(contentEdgeInsets); + + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + if (orientation == LGPlusButtonsViewOrientationAll) { - LGPlusButton *button = _buttons[i]; - - if (![button.titleLabel.text isEqualToString:titles[i]]) - { - [button setTitle:titles[i] forState:state]; - - isChanged = YES; - } + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationPortrait]]; + [_contentEdgeInsetsDictionary setObject:contentEdgeInsetsString forKey:[LGPlusButtonsViewShared stringFromOrientation:LGPlusButtonsViewOrientationLandscape]]; } - - if (isChanged) [self layoutInvalidate]; -} -- (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state -{ - for (LGPlusButton *button in _buttons) - [button setTitleColor:titleColor forState:state]; + [self setNeedsLayout]; } -- (void)setButtonsImage:(UIImage *)image forState:(UIControlState)state +- (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)orientation { - BOOL isChanged = NO; - - for (LGPlusButton *button in _buttons) - { - if (!CGSizeEqualToSize(button.imageView.image.size, image.size)) - isChanged = YES; - - [button setImage:image forState:state]; - } - - if (isChanged) [self layoutInvalidate]; + NSString *contentEdgeInsetsString = [_contentEdgeInsetsDictionary objectForKey:[LGPlusButtonsViewShared stringFromOrientation:orientation]]; + + return (contentEdgeInsetsString ? UIEdgeInsetsFromString(contentEdgeInsetsString) : UIEdgeInsetsZero); } -- (void)setButtonsImages:(NSArray *)images forState:(UIControlState)state +#pragma mark Buttons all + +- (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state { - BOOL isChanged = NO; + NSAssert(_buttonsArray.count == titles.count, kLGPlusButtonsViewAssertionWarning(@"titles")); - for (NSUInteger i=0; i<_buttons.count; i++) - { - LGPlusButton *button = _buttons[i]; - UIImage *image = images[i]; + for (NSUInteger i=0; i<_buttonsArray.count; i++) + if ([titles[i] isKindOfClass:[NSString class]]) + [_buttonsArray[i] setTitle:titles[i] forState:state]; - if (!CGSizeEqualToSize(button.imageView.image.size, image.size)) - isChanged = YES; + [self setNeedsLayout]; +} - [button setImage:image forState:state]; - } +- (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state +{ + for (LGPlusButton *button in _buttonsArray) + [button setTitleColor:titleColor forState:state]; +} + +- (void)setButtonsTitleColors:(NSArray *)titleColors forState:(UIControlState)state +{ + NSAssert(_buttonsArray.count == titleColors.count, kLGPlusButtonsViewAssertionWarning(@"title colors")); - if (isChanged) [self layoutInvalidate]; + for (NSUInteger i=0; i<_buttonsArray.count; i++) + if ([titleColors[i] isKindOfClass:[UIColor class]]) + [_buttonsArray[i] setTitleColor:titleColors[i] forState:state]; } - (void)setButtonsBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state { - for (LGPlusButton *button in _buttons) + for (LGPlusButton *button in _buttonsArray) [button setBackgroundImage:backgroundImage forState:state]; } - (void)setButtonsBackgroundImages:(NSArray *)backgroundImages forState:(UIControlState)state { - for (NSUInteger i=0; i<_buttons.count; i++) - { - LGPlusButton *button = _buttons[i]; - UIImage *backgroundImage = backgroundImages[i]; + NSAssert(_buttonsArray.count == backgroundImages.count, kLGPlusButtonsViewAssertionWarning(@"background images")); - [button setBackgroundImage:backgroundImage forState:state]; - } + for (NSUInteger i=0; i<_buttonsArray.count; i++) + if ([backgroundImages[i] isKindOfClass:[UIImage class]]) + [_buttonsArray[i] setBackgroundImage:backgroundImages[i] forState:state]; } - (void)setButtonsBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { - for (LGPlusButton *button in _buttons) + for (LGPlusButton *button in _buttonsArray) [button setBackgroundColor:backgroundColor forState:state]; } - (void)setButtonsBackgroundColors:(NSArray *)backgroundColors forState:(UIControlState)state { - for (NSUInteger i=0; i<_buttons.count; i++) - { - LGPlusButton *button = _buttons[i]; - UIColor *backgroundColor = backgroundColors[i]; + NSAssert(_buttonsArray.count == backgroundColors.count, kLGPlusButtonsViewAssertionWarning(@"background colors")); - [button setBackgroundColor:backgroundColor forState:state]; - } + for (NSUInteger i=0; i<_buttonsArray.count; i++) + if ([backgroundColors[i] isKindOfClass:[UIColor class]]) + [_buttonsArray[i] setBackgroundColor:backgroundColors[i] forState:state]; } -- (void)setButtonsTitleFont:(UIFont *)font +- (void)setButtonsImage:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation { - BOOL isChanged = NO; - - for (LGPlusButton *button in _buttons) - if (![button.titleLabel.font isEqual:font]) - { - button.titleLabel.font = font; - - isChanged = YES; - } - - if (isChanged) [self layoutInvalidate]; + for (LGPlusButton *button in _buttonsArray) + [button setImage:image forState:state forOrientation:orientation]; + + [self setNeedsLayout]; } -- (void)setButtonsImageViewContentMode:(UIViewContentMode)contentMode +- (void)setButtonsImages:(NSArray *)images forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation { - for (LGPlusButton *button in _buttons) - button.imageView.contentMode = contentMode; + NSAssert(_buttonsArray.count == images.count, kLGPlusButtonsViewAssertionWarning(@"images")); + + for (NSUInteger i=0; i<_buttonsArray.count; i++) + if ([images[i] isKindOfClass:[UIImage class]]) + [_buttonsArray[i] setImage:images[i] forState:state forOrientation:orientation]; + + [self setNeedsLayout]; } -#pragma mark - +#pragma mark // -- (void)setDescriptionsTexts:(NSArray *)texts +- (void)setButtonsTitleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation { - BOOL isChanged = NO; - - for (NSUInteger i=0; i<_descriptions.count; i++) - { - UILabel *label = _descriptions[i]; - - if (![label.text isEqualToString:texts[i]]) - { - label.text = texts[i]; - - isChanged = YES; - } - } - - if (isChanged) [self layoutInvalidate]; + for (LGPlusButton *button in _buttonsArray) + [button setTitleFont:font forOrientation:orientation]; + + [self setNeedsLayout]; } -- (void)setDescriptionsTextColor:(UIColor *)textColor +- (void)setButtonsInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation { - for (UILabel *label in _descriptions) - label.textColor = textColor; + for (LGPlusButton *button in _buttonsArray) + [button setInsets:insets forOrientation:orientation]; + + [self setNeedsLayout]; } -- (void)setDescriptionsBackgroundColor:(UIColor *)backgroundColor +- (void)setButtonsOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation { - for (UILabel *label in _descriptions) - label.backgroundColor = backgroundColor; + for (LGPlusButton *button in _buttonsArray) + [button setOffset:offset forOrientation:orientation]; + + [self setNeedsLayout]; } -- (void)setDescriptionsFont:(UIFont *)font +- (void)setButtonsSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation { - BOOL isChanged = NO; - - for (UILabel *label in _descriptions) - if (![label.font isEqual:font]) - { - label.font = font; - - isChanged = YES; - } - - if (isChanged) [self layoutInvalidate]; + for (LGPlusButton *button in _buttonsArray) + [button setSize:size forOrientation:orientation]; + + [self setNeedsLayout]; } -- (void)setDescriptionOffsetX:(CGFloat)descriptionOffsetX +- (void)setButtonsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation { - if (_descriptionOffsetX != descriptionOffsetX) - { - _descriptionOffsetX = descriptionOffsetX; - - [self layoutInvalidate]; - } + for (LGPlusButton *button in _buttonsArray) + [button setContentEdgeInsets:contentEdgeInsets forOrientation:orientation]; } -#pragma mark - +- (void)setButtonsTitleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButton *button in _buttonsArray) + [button setTitleOffset:titleOffset forOrientation:orientation]; +} -- (void)setButtonsClipsToBounds:(BOOL)clipsToBounds +- (void)setButtonsImageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation { - for (LGPlusButton *button in _buttons) - button.clipsToBounds = clipsToBounds; + for (LGPlusButton *button in _buttonsArray) + [button setImageOffset:imageOffset forOrientation:orientation]; +} + +#pragma mark // + +- (void)setButtonsImageViewContentMode:(UIViewContentMode)contentMode +{ + for (LGPlusButton *button in _buttonsArray) + button.imageView.contentMode = contentMode; } -- (void)setButtonsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets +- (void)setButtonsClipsToBounds:(BOOL)clipsToBounds { - BOOL isChanged = NO; - - for (LGPlusButton *button in _buttons) - if (!UIEdgeInsetsEqualToEdgeInsets(button.contentEdgeInsets, contentEdgeInsets)) - { - button.contentEdgeInsets = contentEdgeInsets; - - isChanged = YES; - } - - if (isChanged) [self layoutInvalidate]; + for (LGPlusButton *button in _buttonsArray) + button.clipsToBounds = clipsToBounds; } - (void)setButtonsAdjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted { - for (LGPlusButton *button in _buttons) + for (LGPlusButton *button in _buttonsArray) button.adjustsImageWhenHighlighted = adjustsImageWhenHighlighted; } -#pragma mark - - -- (void)setButtonsLayerShouldRasterize:(BOOL)shouldRasterize +- (void)setButtonsAdjustsImageWhenDisabled:(BOOL)adjustsImageWhenDisabled { - for (LGPlusButton *button in _buttons) - button.layer.shouldRasterize = shouldRasterize; + for (LGPlusButton *button in _buttonsArray) + button.adjustsImageWhenDisabled = adjustsImageWhenDisabled; } -- (void)setButtonsLayerMasksToBounds:(BOOL)masksToBounds +- (void)setButtonsEnabled:(BOOL)enabled { - for (LGPlusButton *button in _buttons) - button.layer.masksToBounds = masksToBounds; + for (LGPlusButton *button in _buttonsArray) + button.enabled = enabled; } -- (void)setButtonsLayerCornerRadius:(CGFloat)cornerRadius +#pragma mark // + +- (void)setButtonsLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; { - for (LGPlusButton *button in _buttons) - button.layer.cornerRadius = cornerRadius; + for (LGPlusButton *button in _buttonsArray) + [button setLayerCornerRadius:cornerRadius forOrientation:orientation]; } -- (void)setButtonsLayerBorderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth +- (void)setButtonsLayerBorderColor:(UIColor *)borderColor { - for (LGPlusButton *button in _buttons) - { + for (LGPlusButton *button in _buttonsArray) button.layer.borderColor = borderColor.CGColor; +} + +- (void)setButtonsLayerBorderWidth:(CGFloat)borderWidth +{ + for (LGPlusButton *button in _buttonsArray) button.layer.borderWidth = borderWidth; - } } -- (void)setButtonsLayerShadowColor:(UIColor *)shadowColor shadowOpacity:(float)shadowOpacity shadowOffset:(CGSize)shadowOffset shadowRadius:(CGFloat)shadowRadius +- (void)setButtonsLayerShadowColor:(UIColor *)shadowColor { - for (LGPlusButton *button in _buttons) - { - button.layer.shadowColor = shadowColor.CGColor; - button.layer.shadowOpacity = shadowOpacity; - button.layer.shadowOffset = shadowOffset; - button.layer.shadowRadius = shadowRadius; - } + _buttonsContentView.layer.shadowColor = shadowColor.CGColor; } -#pragma mark - +- (void)setButtonsLayerShadowRadius:(CGFloat)shadowRadius +{ + _buttonsContentView.layer.shadowRadius = shadowRadius; +} -- (void)setContentInset:(UIEdgeInsets)contentInset +- (void)setButtonsLayerShadowOpacity:(CGFloat)shadowOpacity { - if (!UIEdgeInsetsEqualToEdgeInsets(_contentInset, contentInset)) - { - _contentInset = contentInset; - - [self layoutInvalidate]; - } + _buttonsContentView.layer.shadowOpacity = shadowOpacity; } -- (void)setButtonInset:(UIEdgeInsets)buttonInset +- (void)setButtonsLayerShadowOffset:(CGSize)shadowOffset { - if (!UIEdgeInsetsEqualToEdgeInsets(_buttonInset, buttonInset)) - { - _buttonInset = buttonInset; - - [self layoutInvalidate]; - } + _buttonsContentView.layer.shadowOffset = shadowOffset; } -- (void)setButtonsSize:(CGSize)buttonsSize +#pragma mark Button at index + +- (void)setButtonAtIndex:(NSUInteger)index title:(NSString *)title forState:(UIControlState)state { - if (!CGSizeEqualToSize(_buttonsSize, buttonsSize)) - { - _buttonsSize = buttonsSize; - - [self layoutInvalidate]; - } + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setTitle:title forState:state]; + + [self setNeedsLayout]; } -- (void)setPlusButtonSize:(CGSize)plusButtonSize +- (void)setButtonAtIndex:(NSUInteger)index titleColor:(UIColor *)titleColor forState:(UIControlState)state { - if (!CGSizeEqualToSize(_plusButtonSize, plusButtonSize)) - { - _plusButtonSize = plusButtonSize; - - [self layoutInvalidate]; - } + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setTitleColor:titleColor forState:state]; } -- (void)setPosition:(LGPlusButtonsViewPosition)position +- (void)setButtonAtIndex:(NSUInteger)index backgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state { - if (_position != position) - { - _position = position; - - if (_position == LGPlusButtonsViewPositionBottomRight || _position == LGPlusButtonsViewPositionTopRight) - _descriptionsPosition = LGPlusButtondescriptionsPositionLeft; - else - _descriptionsPosition = LGPlusButtondescriptionsPositionRight; - - [self layoutInvalidate]; - } + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setBackgroundImage:backgroundImage forState:state]; } -- (void)setOffset:(CGPoint)offset +- (void)setButtonAtIndex:(NSUInteger)index backgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { - if (!CGPointEqualToPoint(_offset, offset)) - { - _offset = offset; - - [self layoutInvalidate]; - } + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setBackgroundColor:backgroundColor forState:state]; } -#pragma mark - +- (void)setButtonAtIndex:(NSUInteger)index image:(UIImage *)image forState:(UIControlState)state forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setImage:image forState:state forOrientation:orientation]; + + [self setNeedsLayout]; +} + +#pragma mark // -- (void)layoutInvalidate +- (void)setButtonAtIndex:(NSUInteger)index titleFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation { - if (self.superview) - { - UIEdgeInsets parentInset = UIEdgeInsetsZero; - CGPoint parentOffset = CGPointZero; - - if ([_parentView isKindOfClass:[UIScrollView class]]) - { - UIScrollView *parentScrollView = (UIScrollView *)_parentView; - - parentInset = parentScrollView.contentInset; - parentOffset = parentScrollView.contentOffset; - } - - // ----- - - NSMutableArray *buttonsSizeArray = [NSMutableArray new]; - - CGSize selfSize = CGSizeMake(_buttonInset.left+_buttonInset.right+_contentInset.left+_contentInset.right, - (_buttonInset.left+_buttonInset.right)*_buttons.count+_contentInset.top+_contentInset.bottom); - - if (!CGSizeEqualToSize(_buttonsSize, CGSizeZero)) - { - if (!CGSizeEqualToSize(_plusButtonSize, CGSizeZero) && self.isShowsPlusButton) - { - selfSize.width += MAX(_plusButtonSize.width, _buttonsSize.width); - selfSize.height += _plusButtonSize.height+(_buttonsSize.height*_buttons.count-1); - } - else - { - selfSize.width += _buttonsSize.width; - selfSize.height += _buttonsSize.height*_buttons.count; - } - } - else - { - CGFloat width = 0.f; - - for (NSUInteger i=0; i<_buttons.count; i++) - { - if (i == 0 && !CGSizeEqualToSize(_plusButtonSize, CGSizeZero) && self.isShowsPlusButton) - { - [buttonsSizeArray addObject:NSStringFromCGSize(_plusButtonSize)]; - - width = MAX(width, _plusButtonSize.width); - selfSize.height += _plusButtonSize.height; - } - else - { - LGPlusButton *button = _buttons[i]; - - CGSize buttonSize = [button sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - - [buttonsSizeArray addObject:NSStringFromCGSize(buttonSize)]; - - width = MAX(width, buttonSize.width); - selfSize.height += buttonSize.height; - } - } - - selfSize.width += width; - } - - // ----- - - CGPoint selfOrigin = CGPointZero; - if (_position == LGPlusButtonsViewPositionBottomRight) - { - selfOrigin = CGPointMake(_parentView.frame.size.width-parentInset.right-selfSize.width+parentOffset.x, - _parentView.frame.size.height-parentInset.bottom-selfSize.height+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionBottomLeft) - { - selfOrigin = CGPointMake(parentInset.left+parentOffset.x, - _parentView.frame.size.height-parentInset.bottom-selfSize.height+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionTopRight) - { - selfOrigin = CGPointMake(_parentView.frame.size.width-parentInset.right-selfSize.width+parentOffset.x, - parentInset.top+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionTopLeft) - { - selfOrigin = CGPointMake(parentInset.left+parentOffset.x, - parentInset.top+parentOffset.y); - } - selfOrigin.x += _offset.x; - selfOrigin.y += _offset.y; - - CGRect selfFrame = CGRectMake(selfOrigin.x, selfOrigin.y, selfSize.width, selfSize.height); - if ([UIScreen mainScreen].scale == 1.f) selfFrame = CGRectIntegral(selfFrame); - self.frame = selfFrame; - - // ----- - - for (NSUInteger i=0; i<_buttons.count; i++) + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setTitleFont:font forOrientation:orientation]; + + [self setNeedsLayout]; +} + +- (void)setButtonAtIndex:(NSUInteger)index insets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setInsets:insets forOrientation:orientation]; + + [self setNeedsLayout]; +} + +- (void)setButtonAtIndex:(NSUInteger)index offset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setOffset:offset forOrientation:orientation]; + + [self setNeedsLayout]; +} + +- (void)setButtonAtIndex:(NSUInteger)index size:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setSize:size forOrientation:orientation]; + + [self setNeedsLayout]; +} + +- (void)setButtonAtIndex:(NSUInteger)index contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setContentEdgeInsets:contentEdgeInsets forOrientation:orientation]; +} + +- (void)setButtonAtIndex:(NSUInteger)index titleOffset:(CGPoint)titleOffset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setTitleOffset:titleOffset forOrientation:orientation]; +} + +- (void)setButtonAtIndex:(NSUInteger)index imageOffset:(CGPoint)imageOffset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setImageOffset:imageOffset forOrientation:orientation]; +} + +#pragma mark // + +- (void)setButtonAtIndex:(NSUInteger)index imageViewContentMode:(UIViewContentMode)contentMode +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] imageView].contentMode = contentMode; +} + +- (void)setButtonAtIndex:(NSUInteger)index clipsToBounds:(BOOL)clipsToBounds +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setClipsToBounds:clipsToBounds]; +} + +- (void)setButtonAtIndex:(NSUInteger)index adjustsImageWhenHighlighted:(BOOL)adjustsImageWhenHighlighted +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setAdjustsImageWhenHighlighted:adjustsImageWhenHighlighted]; +} + +- (void)setButtonAtIndex:(NSUInteger)index adjustsImageWhenDisabled:(BOOL)adjustsImageWhenDisabled +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setAdjustsImageWhenDisabled:adjustsImageWhenDisabled]; +} + +- (void)setButtonAtIndex:(NSUInteger)index enabled:(BOOL)enabled +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setEnabled:enabled]; +} + +#pragma mark // + +- (void)setButtonAtIndex:(NSUInteger)index layerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation; +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] setLayerCornerRadius:cornerRadius forOrientation:orientation]; +} + +- (void)setButtonAtIndex:(NSUInteger)index layerBorderColor:(UIColor *)borderColor +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] layer].borderColor = borderColor.CGColor; +} + +- (void)setButtonAtIndex:(NSUInteger)index layerBorderWidth:(CGFloat)borderWidth +{ + NSAssert(_buttonsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_buttonsArray[index] layer].borderWidth = borderWidth; +} + +#pragma mark Descriptions all + +- (void)setDescriptionsTexts:(NSArray *)texts +{ + NSAssert(_descriptionsArray.count == texts.count, kLGPlusButtonsViewAssertionWarning(@"texts")); + + for (NSUInteger i=0; i<_descriptionsArray.count; i++) + [_descriptionsArray[i] setText:texts[i]]; + + [self setNeedsLayout]; +} + +- (void)setDescriptionsTextColor:(UIColor *)textColor +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + description.textColor = textColor; +} + +- (void)setDescriptionsBackgroundColor:(UIColor *)backgroundColor +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + description.backgroundColor = backgroundColor; +} + +#pragma mark // + +- (void)setDescriptionsFont:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setFont:font forOrientation:orientation]; +} + +- (void)setDescriptionsInsets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setInsets:insets forOrientation:orientation]; +} + +- (void)setDescriptionsOffset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setOffset:offset forOrientation:orientation]; +} + +- (void)setDescriptionsSize:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setSize:size forOrientation:orientation]; +} + +- (void)setDescriptionsContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setContentEdgeInsets:contentEdgeInsets forOrientation:orientation]; +} + +#pragma mark // + +- (void)setDescriptionsLayerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + [description setLayerCornerRadius:cornerRadius forOrientation:orientation]; +} + +- (void)setDescriptionsLayerBorderColor:(UIColor *)borderColor +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + description.layer.borderColor = borderColor.CGColor; +} + +- (void)setDescriptionsLayerBorderWidth:(CGFloat)borderWidth +{ + for (LGPlusButtonDescription *description in _descriptionsArray) + description.layer.borderWidth = borderWidth; +} + +- (void)setDescriptionsLayerShadowColor:(UIColor *)shadowColor +{ + _descriptionsContentView.layer.shadowColor = shadowColor.CGColor; +} + +- (void)setDescriptionsLayerShadowRadius:(CGFloat)shadowRadius +{ + _descriptionsContentView.layer.shadowRadius = shadowRadius; +} + +- (void)setDescriptionsLayerShadowOpacity:(CGFloat)shadowOpacity +{ + _descriptionsContentView.layer.shadowOpacity = shadowOpacity; +} + +- (void)setDescriptionsLayerShadowOffset:(CGSize)shadowOffset +{ + _descriptionsContentView.layer.shadowOffset = shadowOffset; +} + +#pragma mark Description at index + +- (void)setDescriptionAtIndex:(NSUInteger)index text:(NSString *)text +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setText:text]; + + [self setNeedsLayout]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index textColor:(UIColor *)textColor +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setTextColor:textColor]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index backgroundColor:(UIColor *)backgroundColor +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setBackgroundColor:backgroundColor]; +} + +#pragma mark // + +- (void)setDescriptionAtIndex:(NSUInteger)index font:(UIFont *)font forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setFont:font forOrientation:orientation]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index insets:(UIEdgeInsets)insets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setInsets:insets forOrientation:orientation]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index offset:(CGPoint)offset forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setOffset:offset forOrientation:orientation]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index size:(CGSize)size forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setSize:size forOrientation:orientation]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index contentEdgeInsets:(UIEdgeInsets)contentEdgeInsets forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setContentEdgeInsets:contentEdgeInsets forOrientation:orientation]; +} + +#pragma mark // + +- (void)setDescriptionAtIndex:(NSUInteger)index layerCornerRadius:(CGFloat)cornerRadius forOrientation:(LGPlusButtonsViewOrientation)orientation +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] setLayerCornerRadius:cornerRadius forOrientation:orientation]; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index layerBorderColor:(UIColor *)borderColor +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] layer].borderColor = borderColor.CGColor; +} + +- (void)setDescriptionAtIndex:(NSUInteger)index layerBorderWidth:(CGFloat)borderWidth +{ + NSAssert(_descriptionsArray.count > index, kLGPlusButtonsViewIndexAssertionWarning); + + [_descriptionsArray[index] layer].borderWidth = borderWidth; +} + +#pragma mark - View + +- (void)setPosition:(LGPlusButtonsViewPosition)position +{ + _position = position; + + if (_position == LGPlusButtonsViewPositionBottomRight || _position == LGPlusButtonsViewPositionTopRight) + _descriptionsPosition = LGPlusButtonDescriptionsPositionLeft; + else + _descriptionsPosition = LGPlusButtonDescriptionsPositionRight; + + [self setNeedsLayout]; +} + +- (void)setOffset:(CGPoint)offset +{ + _offset = offset; + + [self setNeedsLayout]; +} + +#pragma mark - + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + // ----- + + LGPlusButtonsViewOrientation orientation = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationLandscape; + + // ----- + + UIEdgeInsets parentInset = UIEdgeInsetsZero; + CGPoint parentOffset = CGPointZero; + + if ([self.superview isKindOfClass:[UIScrollView class]]) + { + UIScrollView *parentScrollView = (UIScrollView *)self.superview; + + parentInset = parentScrollView.contentInset; + parentOffset = parentScrollView.contentOffset; + } + + // ----- + + CGRect selfFrame = CGRectMake(parentOffset.x, parentOffset.y, self.superview.bounds.size.width, self.superview.bounds.size.height); + if ([UIScreen mainScreen].scale == 1.f) + selfFrame = CGRectIntegral(selfFrame); + self.frame = selfFrame; + + _coverView.frame = CGRectMake(0.f, 0.f, selfFrame.size.width, selfFrame.size.height); + + // ----- + + CGSize buttonsContentViewSize = CGSizeZero; + + for (LGPlusButton *button in _buttonsArray) + { + [button updateParametersForOrientation:orientation]; + + if (CGSizeEqualToSize([button sizeForOrientation:orientation], CGSizeZero)) { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[i]; - WrapperView *buttonWrapperView2 = _buttonWrapperViews2[i]; - LGPlusButton *button = _buttons[i]; - - CGRect buttonFrame = CGRectZero; - CGSize buttonSize = CGSizeZero; - - if (i == 0 && !CGSizeEqualToSize(_plusButtonSize, CGSizeZero) && self.isShowsPlusButton) - buttonSize = _plusButtonSize; - else if (!CGSizeEqualToSize(_buttonsSize, CGSizeZero)) - buttonSize = _buttonsSize; - else - buttonSize = CGSizeFromString(buttonsSizeArray[i]); - - if (i == 0) + CGSize size = [button sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; + + [button setSize:size forOrientation:orientation]; + } + + CGSize buttonSize = [button sizeForOrientation:orientation]; + UIEdgeInsets buttonInsets = [button insetsForOrientation:orientation]; + + buttonsContentViewSize.width = MAX(buttonsContentViewSize.width, buttonSize.width + buttonInsets.left + buttonInsets.right); + buttonsContentViewSize.height += [button sizeForOrientation:orientation].height + buttonInsets.top + buttonInsets.bottom; + } + + // ----- + + UIEdgeInsets contentEdgeInsets = [self contentEdgeInsetsForOrientation:orientation]; + + CGRect contentViewFrame = CGRectMake(parentInset.left+contentEdgeInsets.left, + parentInset.top+contentEdgeInsets.top, + selfFrame.size.width-parentInset.left-parentInset.right-contentEdgeInsets.left-contentEdgeInsets.right, + selfFrame.size.height-parentInset.top-parentInset.bottom-contentEdgeInsets.top-contentEdgeInsets.bottom); + if ([UIScreen mainScreen].scale == 1.f) + contentViewFrame = CGRectIntegral(contentViewFrame); + _contentView.frame = contentViewFrame; + + // ----- + + CGPoint buttonsContentViewOrigin = CGPointZero; + if (_position == LGPlusButtonsViewPositionBottomRight) + buttonsContentViewOrigin = CGPointMake(contentViewFrame.size.width-buttonsContentViewSize.width, contentViewFrame.size.height-buttonsContentViewSize.height); + else if (_position == LGPlusButtonsViewPositionBottomLeft) + buttonsContentViewOrigin = CGPointMake(0.f, contentViewFrame.size.height-buttonsContentViewSize.height); + else if (_position == LGPlusButtonsViewPositionTopRight) + buttonsContentViewOrigin = CGPointMake(contentViewFrame.size.width-buttonsContentViewSize.width, 0.f); + else if (_position == LGPlusButtonsViewPositionTopLeft) + buttonsContentViewOrigin = CGPointMake(0.f, 0.f); + + buttonsContentViewOrigin.x += _offset.x; + buttonsContentViewOrigin.y += _offset.y; + + CGRect buttonsContentViewFrame = CGRectMake(buttonsContentViewOrigin.x, buttonsContentViewOrigin.y, buttonsContentViewSize.width, buttonsContentViewSize.height); + if ([UIScreen mainScreen].scale == 1.f) + buttonsContentViewFrame = CGRectIntegral(buttonsContentViewFrame); + _buttonsContentView.frame = buttonsContentViewFrame; + + // ----- + + CGRect descriptionsContentViewFrame = CGRectZero; + + if (_descriptionsPosition == LGPlusButtonDescriptionsPositionLeft) + descriptionsContentViewFrame = CGRectMake(0.f, + buttonsContentViewFrame.origin.y, + contentViewFrame.size.width-buttonsContentViewFrame.size.width, + buttonsContentViewFrame.size.height); + else + descriptionsContentViewFrame = CGRectMake(buttonsContentViewFrame.origin.x+buttonsContentViewFrame.size.width, + buttonsContentViewFrame.origin.y, + contentViewFrame.size.width-(buttonsContentViewFrame.origin.x+buttonsContentViewFrame.size.width), + buttonsContentViewFrame.size.height); + + if ([UIScreen mainScreen].scale == 1.f) + descriptionsContentViewFrame = CGRectIntegral(descriptionsContentViewFrame); + _descriptionsContentView.frame = descriptionsContentViewFrame; + + // ----- + + for (NSUInteger i=0; i<_buttonsArray.count; i++) + { + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[i]; + WrapperView *buttonWrapperView2 = _buttonWrapperViewsArray2[i]; + LGPlusButton *button = _buttonsArray[i]; + + CGSize buttonSize = [button sizeForOrientation:orientation]; + UIEdgeInsets buttonInsets = [button insetsForOrientation:orientation]; + CGPoint buttonOffset = [button offsetForOrientation:orientation]; + + CGRect buttonFrame = CGRectZero; + + if (i == 0) + { + if (_position == LGPlusButtonsViewPositionBottomRight) + buttonFrame = CGRectMake(buttonsContentViewSize.width-buttonInsets.right-buttonSize.width, + buttonsContentViewFrame.size.height-buttonInsets.bottom-buttonSize.height, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionBottomLeft) + buttonFrame = CGRectMake(buttonInsets.left, + buttonsContentViewFrame.size.height-buttonInsets.bottom-buttonSize.height, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionTopRight) + buttonFrame = CGRectMake(buttonsContentViewSize.width-buttonInsets.right-buttonSize.width, + buttonInsets.top, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionTopLeft) + buttonFrame = CGRectMake(buttonInsets.left, + buttonInsets.top, + buttonSize.width, + buttonSize.height); + } + else + { + CGRect previousWrapperFrame = [_buttonWrapperViewsArray1[i-1] frame]; + + if (_position == LGPlusButtonsViewPositionBottomRight) + buttonFrame = CGRectMake(buttonsContentViewSize.width-buttonInsets.right-buttonSize.width, + previousWrapperFrame.origin.y-buttonInsets.top-buttonInsets.bottom-buttonSize.height, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionBottomLeft) + buttonFrame = CGRectMake(buttonInsets.left, + previousWrapperFrame.origin.y-buttonInsets.top-buttonInsets.bottom-buttonSize.height, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionTopRight) + buttonFrame = CGRectMake(buttonsContentViewSize.width-buttonInsets.right-buttonSize.width, + previousWrapperFrame.origin.y+previousWrapperFrame.size.height+buttonInsets.bottom+buttonInsets.top, + buttonSize.width, + buttonSize.height); + else if (_position == LGPlusButtonsViewPositionTopLeft) + buttonFrame = CGRectMake(buttonInsets.left, + previousWrapperFrame.origin.y+previousWrapperFrame.size.height+buttonInsets.bottom+buttonInsets.top, + buttonSize.width, + buttonSize.height); + } + + buttonFrame.origin.x += buttonOffset.x; + buttonFrame.origin.y += buttonOffset.y; + + if ([UIScreen mainScreen].scale == 1.f) + buttonFrame = CGRectIntegral(buttonFrame); + + buttonWrapperView1.transform = CGAffineTransformIdentity; + buttonWrapperView1.frame = buttonFrame; + + buttonWrapperView2.frame = CGRectMake(buttonWrapperView1.frame.size.width/2, buttonWrapperView1.frame.size.height/2, 0.f, 0.f); + + button.frame = CGRectMake(-buttonWrapperView1.frame.size.width/2, -buttonWrapperView1.frame.size.height/2, buttonWrapperView1.frame.size.width, buttonWrapperView1.frame.size.height); + } + + // ----- + + for (NSUInteger i=0; i<_descriptionsArray.count; i++) + { + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[i]; + LGPlusButton *button = _buttonsArray[i]; + + CGSize buttonSize = [button sizeForOrientation:orientation]; + UIEdgeInsets buttonInsets = [button insetsForOrientation:orientation]; + + UIView *descriptionWrapperView = _descriptionWrapperViewsArray[i]; + LGPlusButtonDescription *description = _descriptionsArray[i]; + + description.textAlignment = (_descriptionsPosition == LGPlusButtonDescriptionsPositionLeft ? NSTextAlignmentRight : NSTextAlignmentLeft); + [description updateParametersForOrientation:orientation]; + + UIEdgeInsets descriptionInsets = [description insetsForOrientation:orientation]; + CGPoint descriptionOffset = [description offsetForOrientation:orientation]; + + if (description.text.length) + { + if (CGSizeEqualToSize([description sizeForOrientation:orientation], CGSizeZero)) { - if (_position == LGPlusButtonsViewPositionBottomRight) - { - buttonFrame = CGRectMake(selfFrame.size.width-_contentInset.right-_buttonInset.right-buttonSize.width, - selfFrame.size.height-_contentInset.bottom-_buttonInset.bottom-buttonSize.height, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionBottomLeft) - { - buttonFrame = CGRectMake(_contentInset.left+_buttonInset.left, - selfFrame.size.height-_contentInset.bottom-_buttonInset.bottom-buttonSize.height, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionTopRight) - { - buttonFrame = CGRectMake(selfFrame.size.width-_contentInset.right-_buttonInset.right-buttonSize.width, - _contentInset.top+_buttonInset.top, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionTopLeft) - { - buttonFrame = CGRectMake(_contentInset.left+_buttonInset.left, - _contentInset.top+_buttonInset.top, - buttonSize.width, - buttonSize.height); - } + CGSize size = [description sizeThatFits:CGSizeMake(descriptionsContentViewFrame.size.width, CGFLOAT_MAX)]; + + [description setSize:size forOrientation:orientation]; + } + + CGSize descriptionSize = [description sizeForOrientation:orientation]; + + descriptionWrapperView.transform = CGAffineTransformIdentity; + CGRect descriptionWrapperViewFrame = buttonWrapperView1.frame; + + CGRect descriptionFrame = CGRectZero; + + if (_descriptionsPosition == LGPlusButtonDescriptionsPositionLeft) + { + descriptionWrapperViewFrame.origin.x = descriptionsContentViewFrame.size.width+buttonInsets.left; + descriptionWrapperView.frame = descriptionWrapperViewFrame; + + descriptionFrame = CGRectMake(-buttonInsets.left-descriptionInsets.right-descriptionSize.width, + descriptionWrapperView.frame.size.height/2.f-descriptionSize.height/2.f, + descriptionSize.width, + descriptionSize.height); } else { - WrapperView *previousWrapperView1 = _buttonWrapperViews1[i-1]; - - if (_position == LGPlusButtonsViewPositionBottomRight) - { - buttonFrame = CGRectMake(selfFrame.size.width-_contentInset.right-_buttonInset.right-buttonSize.width, - previousWrapperView1.frame.origin.y-_buttonInset.top-_buttonInset.bottom-buttonSize.height, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionBottomLeft) - { - buttonFrame = CGRectMake(_contentInset.left+_buttonInset.left, - previousWrapperView1.frame.origin.y-_buttonInset.top-_buttonInset.bottom-buttonSize.height, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionTopRight) - { - buttonFrame = CGRectMake(selfFrame.size.width-_contentInset.right-_buttonInset.right-buttonSize.width, - previousWrapperView1.frame.origin.y+previousWrapperView1.frame.size.height+_buttonInset.bottom+_buttonInset.top, - buttonSize.width, - buttonSize.height); - } - else if (_position == LGPlusButtonsViewPositionTopLeft) - { - buttonFrame = CGRectMake(_contentInset.left+_buttonInset.left, - previousWrapperView1.frame.origin.y+previousWrapperView1.frame.size.height+_buttonInset.bottom+_buttonInset.top, - buttonSize.width, - buttonSize.height); - } + descriptionWrapperViewFrame.origin.x = -buttonSize.width-buttonInsets.right; + descriptionWrapperView.frame = descriptionWrapperViewFrame; + + descriptionFrame = CGRectMake(descriptionWrapperView.frame.size.width+buttonInsets.right+descriptionInsets.left, + descriptionWrapperView.frame.size.height/2.f-descriptionSize.height/2.f, + descriptionSize.width, + descriptionSize.height); } - - if ([UIScreen mainScreen].scale == 1.f) buttonFrame = CGRectIntegral(buttonFrame); - buttonWrapperView1.transform = CGAffineTransformIdentity; - buttonWrapperView1.frame = buttonFrame; - - buttonWrapperView2.frame = CGRectMake(buttonWrapperView1.frame.size.width/2, buttonWrapperView1.frame.size.height/2, 0.f, 0.f); - button.frame = CGRectMake(-buttonWrapperView1.frame.size.width/2, -buttonWrapperView1.frame.size.height/2, buttonWrapperView1.frame.size.width, buttonWrapperView1.frame.size.height); + + descriptionFrame.origin.x += descriptionOffset.x; + descriptionFrame.origin.y += descriptionOffset.y; + + if ([UIScreen mainScreen].scale == 1.f) + descriptionFrame = CGRectIntegral(descriptionFrame); + + description.frame = descriptionFrame; + } - - // ----- - - for (NSUInteger i=0; i<_buttons.count; i++) + else + { + descriptionWrapperView.transform = CGAffineTransformIdentity; + descriptionWrapperView.frame = CGRectZero; + + description.frame = CGRectZero; + } + } + + // ----- + + for (NSUInteger i=0; i<_buttonsArray.count; i++) + { + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[i]; + LGPlusButton *button = _buttonsArray[i]; + + if (CGAffineTransformEqualToTransform(buttonWrapperView1.transform, CGAffineTransformIdentity) && button.frame.size.width > 1.f && button.frame.size.height > 1.f) { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[i]; - LGPlusButton *button = _buttons[i]; - - WrapperView *descriptionWrapperView = _descriptionWrapperViews[i]; - UILabel *label = _descriptions[i]; - - if (label.text.length) + LGPlusButtonsAppearingAnimationType animationType = NSNotFound; + + if (!self.isShowing) { - descriptionWrapperView.transform = CGAffineTransformIdentity; - descriptionWrapperView.frame = CGRectMake(buttonWrapperView1.frame.origin.x+button.contentEdgeInsets.left, - buttonWrapperView1.frame.origin.y+button.contentEdgeInsets.top, - buttonWrapperView1.frame.size.width-button.contentEdgeInsets.left-button.contentEdgeInsets.right, - buttonWrapperView1.frame.size.height-button.contentEdgeInsets.top-button.contentEdgeInsets.bottom); - CGFloat paddingWidth = 8.f; - CGFloat paddingHeight = 4.f; - - CGSize labelSize = [label sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - - CGFloat originX; - if (_descriptionsPosition == LGPlusButtondescriptionsPositionLeft) - originX = -labelSize.width-_descriptionOffsetX-paddingWidth*2; + if (self.isFirstButtonIsPlusButton) + { + if (i == 0) + animationType = _appearingAnimationType; + else + { + if (button.isShowing) + animationType = _appearingAnimationType; + else + animationType = _buttonsAppearingAnimationType; + } + } else - originX = descriptionWrapperView.frame.size.width+_descriptionOffsetX; - - CGRect labelFrame = CGRectMake(originX, - descriptionWrapperView.frame.size.height/2-labelSize.height/2-paddingHeight, - labelSize.width+paddingWidth*2, - labelSize.height+paddingHeight*2); - if ([UIScreen mainScreen].scale == 1.f) labelFrame = CGRectIntegral(labelFrame); - label.frame = labelFrame; + { + if (!button.isShowing) + animationType = _appearingAnimationType; + } } else { - descriptionWrapperView.transform = CGAffineTransformIdentity; - descriptionWrapperView.frame = CGRectZero; - - label.frame = CGRectZero; + if (self.isFirstButtonIsPlusButton) + { + if (!button.isShowing) + animationType = _buttonsAppearingAnimationType; + } } - } - - // ----- - - for (NSUInteger i=0; i<_buttons.count; i++) - { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[i]; - LGPlusButton *button = _buttons[i]; - - if (!button.isShowing && CGAffineTransformEqualToTransform(buttonWrapperView1.transform, CGAffineTransformIdentity) && button.frame.size.width > 1.f && button.frame.size.height > 1.f) - [self hideAnimationsWithButtonAtIndex:i animationType:((i == 0 || !self.isShowsPlusButton) ? _appearingAnimationType : _buttonsAppearingAnimationType)]; + + if (animationType != NSNotFound) + [self hideAnimationsWithButtonAtIndex:i animationType:animationType]; } } } - (void)updatePosition { - if (self.superview) - { - UIEdgeInsets parentInset = UIEdgeInsetsZero; - CGPoint parentOffset = CGPointZero; - - if ([_parentView isKindOfClass:[UIScrollView class]]) - { - UIScrollView *parentScrollView = (UIScrollView *)_parentView; - - parentInset = parentScrollView.contentInset; - parentOffset = parentScrollView.contentOffset; - } - - CGPoint selfOrigin = CGPointZero; - if (_position == LGPlusButtonsViewPositionBottomRight) - { - selfOrigin = CGPointMake(_parentView.frame.size.width-parentInset.right-self.frame.size.width+parentOffset.x, - _parentView.frame.size.height-parentInset.bottom-self.frame.size.height+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionBottomLeft) - { - selfOrigin = CGPointMake(parentInset.left+parentOffset.x, - _parentView.frame.size.height-parentInset.bottom-self.frame.size.height+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionTopRight) - { - selfOrigin = CGPointMake(_parentView.frame.size.width-parentInset.right-self.frame.size.width+parentOffset.x, - parentInset.top+parentOffset.y); - } - else if (_position == LGPlusButtonsViewPositionTopLeft) - { - selfOrigin = CGPointMake(parentInset.left+parentOffset.x, - parentInset.top+parentOffset.y); - } - selfOrigin.x += _offset.x; - selfOrigin.y += _offset.y; - - CGRect selfFrame = CGRectMake(selfOrigin.x, selfOrigin.y, self.frame.size.width, self.frame.size.height); - if ([UIScreen mainScreen].scale == 1.f) selfFrame = CGRectIntegral(selfFrame); - self.center = CGPointMake(selfFrame.origin.x+selfFrame.size.width/2, selfFrame.origin.y+selfFrame.size.height/2); - } + UIScrollView *parentScrollView = (UIScrollView *)self.superview; + + CGPoint parentOffset = parentScrollView.contentOffset; + + self.center = CGPointMake(parentOffset.x+parentScrollView.frame.size.width/2.f, parentOffset.y+parentScrollView.frame.size.height/2); } #pragma mark - Actions -- (void)plusButtonAction:(LGPlusButton *)button +- (void)tapGesture:(UITapGestureRecognizer *)gestureRecognizer { - if (_plusButton.isSelected) + if (self.isFirstButtonIsPlusButton) [self hideButtonsAnimated:YES completionHandler:nil]; else - [self showButtonsAnimated:YES completionHandler:nil]; - - if (_plusButtonActionHandler) _plusButtonActionHandler(self); - - if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewPlusButtonPressed:)]) - [_delegate plusButtonsViewPlusButtonPressed:self]; + [self hideAnimated:YES completionHandler:nil]; } - (void)buttonAction:(LGPlusButton *)button { - NSUInteger index = [_buttons indexOfObject:button]; - - UILabel *descriptionLabel = _descriptions[index]; - - if (_actionHandler) _actionHandler(self, button.titleLabel.text, descriptionLabel.text, button.tag); - + NSUInteger index = button.tag; + + LGPlusButtonDescription *description = _descriptionsArray[index]; + + if (self.isFirstButtonIsPlusButton && index == 0) + { + if (button.isSelected) + [self hideButtonsAnimated:YES completionHandler:nil]; + else + [self showButtonsAnimated:YES completionHandler:nil]; + } + + // ----- + + if (_actionHandler) _actionHandler(self, button.titleLabel.text, description.text, button.tag); + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsView:buttonPressedWithTitle:description:index:)]) - [_delegate plusButtonsView:self buttonPressedWithTitle:button.titleLabel.text description:descriptionLabel.text index:button.tag]; + [_delegate plusButtonsView:self buttonPressedWithTitle:button.titleLabel.text description:description.text index:button.tag]; + + NSMutableDictionary *userInfo = [NSMutableDictionary new]; + if (button.titleLabel.text) + [userInfo setObject:button.titleLabel.text forKey:@"title"]; + if (description.text) + [userInfo setObject:description.text forKey:@"description"]; + if (button.tag != NSNotFound) + [userInfo setObject:[NSNumber numberWithInteger:button.tag] forKey:@"index"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewActionNotification object:self userInfo:userInfo]; } #pragma mark - Animations @@ -990,49 +1297,61 @@ - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl if (!self.isShowing) { _showing = YES; - _plusButton.showing = YES; - self.hidden = NO; - - NSTimeInterval delay = 0.03; - - if (self.isShowsPlusButton) - { - for (NSInteger i=0; i<_buttons.count; i++) - { - LGPlusButton *button = _buttons[i]; - - if (i == 0 || (i > 0 && button.isShowing)) - { - [self showButtonAtIndex:i - animationType:_appearingAnimationType - delay:delay*i - animated:animated - completionHandler:^(BOOL result) - { - if (completionHandler) completionHandler(); - }]; - } - } - } - else + + // ----- + + if (_willShowHandler) _willShowHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewWillShow:)]) + [_delegate plusButtonsViewWillShow:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewWillShowNotification object:self userInfo:nil]; + + // ----- + + NSTimeInterval delay = _appearingAnimationSpeed/10.f; + + for (NSInteger i=0; i<_buttonsArray.count; i++) { - for (NSInteger i=0; i<_buttons.count; i++) + LGPlusButton *button = _buttonsArray[i]; + + if (!self.isFirstButtonIsPlusButton || + (self.isFirstButtonIsPlusButton && (i == 0 || (i > 0 && button.isShowing)))) { - LGPlusButton *button = _buttons[i]; - - button.showing = YES; - + if (!self.isFirstButtonIsPlusButton || + (self.isFirstButtonIsPlusButton && i == 0)) + button.showing = YES; + + __block NSUInteger index = i; + [self showButtonAtIndex:i animationType:_appearingAnimationType delay:delay*i + animationSpeed:_appearingAnimationSpeed animated:animated completionHandler:^(BOOL result) { - if (completionHandler) completionHandler(); + if (result && index == _buttonsArray.count-1) + { + if (completionHandler) completionHandler(); + + // ----- + + if (_didShowHandler) _didShowHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewDidShow:)]) + [_delegate plusButtonsViewDidShow:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewDidShowNotification object:self userInfo:nil]; + } }]; } } + + if (!self.isFirstButtonIsPlusButton) + [self showCoverViewAnimated:animated + animationType:_appearingAnimationType]; } } @@ -1040,62 +1359,63 @@ - (void)hideAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl { if (self.isShowing) { - if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewShouldHide:)]) { - if (![_delegate plusButtonsViewShouldHide:self]) - return; - } _showing = NO; - _plusButton.showing = NO; - - NSTimeInterval delay = 0.03; - - if (self.isShowsPlusButton) - { - for (NSInteger i=0; i<_buttons.count; i++) - { - LGPlusButton *button = _buttons[i]; - - if (i == 0 || (i > 0 && button.isShowing)) - { - __block NSUInteger index = i; - - [self hideButtonAtIndex:i - animationType:_appearingAnimationType - delay:delay*i - animated:animated - completionHandler:^(BOOL result) - { - if (result && index == _buttons.count-1) - self.hidden = YES; - - if (completionHandler && result) completionHandler(); - }]; - } - } - } - else + + // ----- + + if (_willHideHandler) _willHideHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewWillHide:)]) + [_delegate plusButtonsViewWillHide:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewWillHideNotification object:self userInfo:nil]; + + // ----- + + NSTimeInterval delay = _appearingAnimationSpeed/10.f; + + for (NSInteger i=0; i<_buttonsArray.count; i++) { - for (NSInteger i=0; i<_buttons.count; i++) + LGPlusButton *button = _buttonsArray[i]; + + if (!self.isFirstButtonIsPlusButton || + (self.isFirstButtonIsPlusButton && (i == 0 || (i > 0 && button.isShowing)))) { - LGPlusButton *button = _buttons[i]; - - button.showing = NO; - + if (!self.isFirstButtonIsPlusButton || + (self.isFirstButtonIsPlusButton && i == 0)) + button.showing = NO; + __block NSUInteger index = i; - + [self hideButtonAtIndex:i animationType:_appearingAnimationType delay:delay*i + animationSpeed:_appearingAnimationSpeed animated:animated completionHandler:^(BOOL result) { - if (result && index == _buttons.count-1) + if (result && index == _buttonsArray.count-1) + { self.hidden = YES; - - if (completionHandler && result) completionHandler(); + + if (completionHandler) completionHandler(); + + // ----- + + if (_didHideHandler) _didHideHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewDidHide:)]) + [_delegate plusButtonsViewDidHide:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewDidHideNotification object:self userInfo:nil]; + } }]; } } + + if (!self.isFirstButtonIsPlusButton) + [self hideCoverViewAnimated:animated + animationType:_appearingAnimationType]; } } @@ -1103,77 +1423,205 @@ - (void)hideAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl - (void)showButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (self.isShowsPlusButton) + if (self.isFirstButtonIsPlusButton) { - _plusButton.selected = YES; - - [self selectPlusButtonViewWithAnimationType:_plusButtonAnimationType animated:YES completionHandler:nil]; - - NSTimeInterval delay = 0.03; - - for (NSInteger i=1; i<_buttons.count; i++) + LGPlusButton *plusButton = _buttonsArray[0]; + plusButton.selected = YES; + + [self selectPlusButtonViewWithAnimationType:_plusButtonAnimationType + animated:animated + completionHandler:nil]; + + // ----- + + if (_willShowButtonsHandler) _willShowButtonsHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewWillShowButtons:)]) + [_delegate plusButtonsViewWillShowButtons:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewWillShowButtonsNotification object:self userInfo:nil]; + + // ----- + + NSTimeInterval delay = _buttonsAppearingAnimationSpeed/10.f; + + for (NSInteger i=1; i<_buttonsArray.count; i++) { - LGPlusButton *button = _buttons[i]; - + LGPlusButton *button = _buttonsArray[i]; + if (!button.isShowing) { button.showing = YES; - - if (_plusButton.isShowing) - { - [self showButtonAtIndex:i - animationType:_buttonsAppearingAnimationType - delay:delay*(i-1) - animated:animated - completionHandler:^(BOOL result) - { - if (completionHandler && result) completionHandler(); - }]; - } - else - { - [self hideButtonAtIndex:i - animationType:_appearingAnimationType - delay:delay*(i-1) - animated:animated - completionHandler:^(BOOL result) + + __block NSUInteger index = i; + + [self showButtonAtIndex:i + animationType:_buttonsAppearingAnimationType + delay:delay*(i-1) + animationSpeed:_buttonsAppearingAnimationSpeed + animated:animated + completionHandler:^(BOOL result) + { + if (result && index == _buttonsArray.count) { - if (completionHandler && result) completionHandler(); - }]; - } + if (completionHandler) completionHandler(); + + // ----- + + if (_didShowButtonsHandler) _didShowButtonsHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewDidShowButtons:)]) + [_delegate plusButtonsViewDidShowButtons:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewDidShowButtonsNotification object:self userInfo:nil]; + } + }]; } } + + [self showCoverViewAnimated:animated + animationType:_buttonsAppearingAnimationType]; } } - (void)hideButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (self.isShowsPlusButton) + if (self.isFirstButtonIsPlusButton) { - _plusButton.selected = NO; - - [self deselectPlusButtonViewWithAnimationType:_plusButtonAnimationType animated:YES completionHandler:nil]; - - NSTimeInterval delay = 0.03; - - for (NSInteger i=1; i<_buttons.count; i++) + LGPlusButton *plusButton = _buttonsArray[0]; + plusButton.selected = NO; + + [self deselectPlusButtonViewWithAnimationType:_plusButtonAnimationType + animated:animated + completionHandler:nil]; + + // ----- + + if (_willHideButtonsHandler) _willHideButtonsHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewWillHideButtons:)]) + [_delegate plusButtonsViewWillHideButtons:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewWillHideButtonsNotification object:self userInfo:nil]; + + // ----- + + NSTimeInterval delay = _buttonsAppearingAnimationSpeed/10.f; + + for (NSInteger i=1; i<_buttonsArray.count; i++) { - LGPlusButton *button = _buttons[i]; - + LGPlusButton *button = _buttonsArray[i]; + if (button.isShowing) { button.showing = NO; - + + __block NSUInteger index = i; + [self hideButtonAtIndex:i animationType:_buttonsAppearingAnimationType delay:delay*(i-1) + animationSpeed:_buttonsAppearingAnimationSpeed animated:animated completionHandler:^(BOOL result) { - if (completionHandler && result) completionHandler(); + if (result && index == _buttonsArray.count) + { + if (completionHandler) completionHandler(); + + // ----- + + if (_didHideButtonsHandler) _didHideButtonsHandler(self); + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsViewDidHideButtons:)]) + [_delegate plusButtonsViewDidHideButtons:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGPlusButtonsViewDidHideButtonsNotification object:self userInfo:nil]; + } }]; } } + + [self hideCoverViewAnimated:animated + animationType:_buttonsAppearingAnimationType]; + } +} + +#pragma mark - Cover View Animations + +- (void)showCoverViewAnimated:(BOOL)animated + animationType:(LGPlusButtonsAppearingAnimationType)type +{ + if (_coverColor && ![_coverColor isEqual:[UIColor clearColor]]) + { + _coverView.hidden = NO; + + if ([self.superview isKindOfClass:[UIScrollView class]]) + [(UIScrollView *)self.superview setScrollEnabled:NO]; + + _coverView.alpha = [(CALayer *)_coverView.layer.presentationLayer opacity]; + [_coverView.layer removeAllAnimations]; + + if (!animated || type == LGPlusButtonsAppearingAnimationTypeNone) + { + _coverView.alpha = 1.f; + } + else + { + NSTimeInterval animationSpeed = (self.isFirstButtonIsPlusButton ? _appearingAnimationSpeed : _buttonsAppearingAnimationSpeed); + CGFloat dif = 1.f-_coverView.alpha; + NSTimeInterval duration = animationSpeed*dif; + + [LGPlusButtonsView animateStandardWithDuration:duration + delay:0.f + animations:^(void) + { + _coverView.alpha = 1.f; + } + completion:nil]; + } + } +} + +- (void)hideCoverViewAnimated:(BOOL)animated + animationType:(LGPlusButtonsAppearingAnimationType)type +{ + if (_coverColor && ![_coverColor isEqual:[UIColor clearColor]]) + { + _coverView.alpha = [(CALayer *)_coverView.layer.presentationLayer opacity]; + [_coverView.layer removeAllAnimations]; + + if (!animated || type == LGPlusButtonsAppearingAnimationTypeNone) + { + _coverView.alpha = 0.f; + _coverView.hidden = YES; + + if ([self.superview isKindOfClass:[UIScrollView class]]) + [(UIScrollView *)self.superview setScrollEnabled:YES]; + } + else + { + NSTimeInterval animationSpeed = (self.isFirstButtonIsPlusButton ? _appearingAnimationSpeed : _buttonsAppearingAnimationSpeed); + CGFloat dif = _coverView.alpha-0.f; + NSTimeInterval duration = animationSpeed*dif; + + [LGPlusButtonsView animateStandardWithDuration:duration + delay:0.f + animations:^(void) + { + _coverView.alpha = 0.f; + } + completion:^(BOOL finished) + { + if (finished) + { + _coverView.hidden = YES; + + if ([self.superview isKindOfClass:[UIScrollView class]]) + [(UIScrollView *)self.superview setScrollEnabled:YES]; + } + }]; + } } } @@ -1182,21 +1630,22 @@ - (void)hideButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completi - (void)showButtonAtIndex:(NSUInteger)index animationType:(LGPlusButtonsAppearingAnimationType)type delay:(NSTimeInterval)delay + animationSpeed:(NSTimeInterval)animationSpeed animated:(BOOL)animated completionHandler:(void(^)(BOOL result))completionHandler { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[index]; - WrapperView *descriptionWrapperView = _descriptionWrapperViews[index]; - + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[index]; + WrapperView *descriptionWrapperView = _descriptionWrapperViewsArray[index]; + // ----- - + CGAffineTransform transform = CGAffineTransformIdentity; - + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop) { CGFloat scaleX = [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.scale.x"] floatValue]; CGFloat scaleY = [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.scale.y"] floatValue]; - + if (scaleX && scaleY) transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(scaleX, scaleY)); } @@ -1205,31 +1654,32 @@ - (void)showButtonAtIndex:(NSUInteger)index transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation([[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.x"] floatValue], [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.y"] floatValue])); } - + buttonWrapperView1.alpha = [(CALayer *)buttonWrapperView1.layer.presentationLayer opacity]; buttonWrapperView1.transform = transform; - + descriptionWrapperView.alpha = buttonWrapperView1.alpha; descriptionWrapperView.transform = buttonWrapperView1.transform; - + // ----- - + [buttonWrapperView1.layer removeAllAnimations]; [descriptionWrapperView.layer removeAllAnimations]; - + // ----- - + if (!animated || type == LGPlusButtonsAppearingAnimationTypeNone) { [self showAnimationsWithButtonAtIndex:index]; - + if (completionHandler) completionHandler(YES); } else { CGFloat dif = 1.f-buttonWrapperView1.alpha; - - [LGPlusButtonsView animateStandardWithDuration:0.3*dif + NSTimeInterval duration = animationSpeed*dif; + + [LGPlusButtonsView animateStandardWithDuration:duration delay:delay animations:^(void) { @@ -1244,16 +1694,16 @@ - (void)showButtonAtIndex:(NSUInteger)index - (void)showAnimationsWithButtonAtIndex:(NSUInteger)index { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[index]; - WrapperView *descriptionWrapperView = _descriptionWrapperViews[index]; - + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[index]; + WrapperView *descriptionWrapperView = _descriptionWrapperViewsArray[index]; + // ----- - + CGAffineTransform transform = CGAffineTransformIdentity; - + buttonWrapperView1.alpha = 1.f; buttonWrapperView1.transform = transform; - + descriptionWrapperView.alpha = buttonWrapperView1.alpha; descriptionWrapperView.transform = buttonWrapperView1.transform; } @@ -1261,21 +1711,22 @@ - (void)showAnimationsWithButtonAtIndex:(NSUInteger)index - (void)hideButtonAtIndex:(NSUInteger)index animationType:(LGPlusButtonsAppearingAnimationType)type delay:(NSTimeInterval)delay + animationSpeed:(NSTimeInterval)animationSpeed animated:(BOOL)animated completionHandler:(void(^)(BOOL result))completionHandler { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[index]; - WrapperView *descriptionWrapperView = _descriptionWrapperViews[index]; - + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[index]; + WrapperView *descriptionWrapperView = _descriptionWrapperViewsArray[index]; + // ----- - + CGAffineTransform transform = CGAffineTransformIdentity; - + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop) { CGFloat scaleX = [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.scale.x"] floatValue]; CGFloat scaleY = [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.scale.y"] floatValue]; - + if (scaleX && scaleY) transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(scaleX, scaleY)); } @@ -1284,25 +1735,25 @@ - (void)hideButtonAtIndex:(NSUInteger)index transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation([[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.x"] floatValue], [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.y"] floatValue])); } - + buttonWrapperView1.alpha = [(CALayer *)buttonWrapperView1.layer.presentationLayer opacity]; buttonWrapperView1.transform = transform; - + descriptionWrapperView.alpha = buttonWrapperView1.alpha; descriptionWrapperView.transform = buttonWrapperView1.transform; - + // ----- - + [buttonWrapperView1.layer removeAllAnimations]; [descriptionWrapperView.layer removeAllAnimations]; - + // ----- - + if (type == LGPlusButtonsAppearingAnimationTypeNone) { [self hideAnimationsWithButtonAtIndex:index animationType:type]; - + if (completionHandler) completionHandler(YES); } else @@ -1310,8 +1761,9 @@ - (void)hideButtonAtIndex:(NSUInteger)index if (animated) { CGFloat dif = buttonWrapperView1.alpha-0.f; - - [UIView animateWithDuration:0.3*0.66*dif + NSTimeInterval duration = animationSpeed*dif*_hideAnimationCoef; + + [UIView animateWithDuration:duration delay:delay options:0 animations:^(void) @@ -1328,7 +1780,7 @@ - (void)hideButtonAtIndex:(NSUInteger)index { [self hideAnimationsWithButtonAtIndex:index animationType:type]; - + if (completionHandler) completionHandler(YES); } } @@ -1337,37 +1789,43 @@ - (void)hideButtonAtIndex:(NSUInteger)index - (void)hideAnimationsWithButtonAtIndex:(NSUInteger)index animationType:(LGPlusButtonsAppearingAnimationType)type { - WrapperView *buttonWrapperView1 = _buttonWrapperViews1[index]; - WrapperView *descriptionWrapperView = _descriptionWrapperViews[index]; - + WrapperView *buttonWrapperView1 = _buttonWrapperViewsArray1[index]; + WrapperView *descriptionWrapperView = _descriptionWrapperViewsArray[index]; + // ----- - + CGAffineTransform transform = CGAffineTransformIdentity; - + if (type == LGPlusButtonsAppearingAnimationTypeNone) { - // + // no transform } else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolve) { - // + // no transform } else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal) { - transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(buttonWrapperView1.frame.size.width, 0.f)); + if (_position == LGPlusButtonsViewPositionRightTop || _position == LGPlusButtonsViewPositionRightBottom) + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(buttonWrapperView1.frame.size.width, 0.f)); + else + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(-buttonWrapperView1.frame.size.width, 0.f)); } else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical) { - transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.f, buttonWrapperView1.frame.size.height)); + if (_position == LGPlusButtonsViewPositionBottomLeft || _position == LGPlusButtonsViewPositionBottomRight) + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.f, buttonWrapperView1.frame.size.height)); + else + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.f, -buttonWrapperView1.frame.size.height)); } else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop) { transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(0.5, 0.5)); } - + buttonWrapperView1.alpha = 0.f; buttonWrapperView1.transform = transform; - + descriptionWrapperView.alpha = buttonWrapperView1.alpha; descriptionWrapperView.transform = buttonWrapperView1.transform; } @@ -1376,15 +1834,15 @@ - (void)hideAnimationsWithButtonAtIndex:(NSUInteger)index - (void)selectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type animated:(BOOL)animated completionHandler:(void(^)(BOOL result))completionHandler { - WrapperView *plusButtonWrapperView2 = _buttonWrapperViews2[0]; - + WrapperView *plusButtonWrapperView2 = _buttonWrapperViewsArray2[0]; + // ----- - + if (type == LGPlusButtonAnimationTypeCrossDissolve) { if (animated) [UIView transitionWithView:plusButtonWrapperView2 - duration:0.2 + duration:_buttonsAppearingAnimationSpeed options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:completionHandler]; @@ -1393,10 +1851,10 @@ - (void)selectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type an { CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformConcat(transform, CGAffineTransformMakeRotation(kLGPlusButtonsViewDegreesToRadians(45))); - + if (animated) { - [UIView animateWithDuration:0.2 + [UIView animateWithDuration:_buttonsAppearingAnimationSpeed animations:^(void) { plusButtonWrapperView2.transform = transform; @@ -1405,7 +1863,7 @@ - (void)selectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type an else { plusButtonWrapperView2.transform = transform; - + if (completionHandler) completionHandler(YES); } } @@ -1413,15 +1871,15 @@ - (void)selectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type an - (void)deselectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type animated:(BOOL)animated completionHandler:(void(^)(BOOL result))completionHandler { - WrapperView *plusButtonWrapperView2 = _buttonWrapperViews2[0]; - + WrapperView *plusButtonWrapperView2 = _buttonWrapperViewsArray2[0]; + // ----- - + if (type == LGPlusButtonAnimationTypeCrossDissolve) { if (animated) [UIView transitionWithView:plusButtonWrapperView2 - duration:0.2 + duration:_buttonsAppearingAnimationSpeed options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:completionHandler]; @@ -1430,7 +1888,7 @@ - (void)deselectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type { if (animated) { - [UIView animateWithDuration:0.2 + [UIView animateWithDuration:_buttonsAppearingAnimationSpeed animations:^(void) { plusButtonWrapperView2.transform = CGAffineTransformIdentity; @@ -1439,7 +1897,7 @@ - (void)deselectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type else { plusButtonWrapperView2.transform = CGAffineTransformIdentity; - + if (completionHandler) completionHandler(YES); } } @@ -1447,34 +1905,58 @@ - (void)deselectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type #pragma mark - Observers -- (void)addObservers +- (void)addObservers:(UIView *)view { - if (!self.isObserversAdded && _parentView) + if (!self.isObserversAdded && view) { _observersAdded = YES; - - [_parentView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil]; - - if ([_parentView isKindOfClass:[UIScrollView class]]) + + [view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil]; + + if ([view isKindOfClass:[UIScrollView class]]) + { + [view addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; + [view addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + [view addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; + } + + if (_observedScrollView) { - [_parentView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; - [_parentView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + NSAssert([_observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); + + _observersForScrollViewAdded = YES; + + [_observedScrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; + [_observedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + [_observedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; } } } -- (void)removeObservers +- (void)removeObservers:(UIView *)view { - if (self.isObserversAdded && _parentView) + if (self.isObserversAdded && view) { _observersAdded = NO; - - [_parentView removeObserver:self forKeyPath:@"frame"]; - - if ([_parentView isKindOfClass:[UIScrollView class]]) + + [view removeObserver:self forKeyPath:@"frame"]; + + if ([view isKindOfClass:[UIScrollView class]]) + { + [view removeObserver:self forKeyPath:@"contentInset"]; + [view removeObserver:self forKeyPath:@"contentOffset"]; + [view removeObserver:self forKeyPath:@"contentSize"]; + } + + if (self.isObserversForScrollViewAdded) { - [_parentView removeObserver:self forKeyPath:@"contentInset"]; - [_parentView removeObserver:self forKeyPath:@"contentOffset"]; + NSAssert([_observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); + + _observersForScrollViewAdded = NO; + + [_observedScrollView removeObserver:self forKeyPath:@"contentInset"]; + [_observedScrollView removeObserver:self forKeyPath:@"contentOffset"]; + [_observedScrollView removeObserver:self forKeyPath:@"contentSize"]; } } } @@ -1482,52 +1964,90 @@ - (void)removeObservers - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"frame"]) - [self layoutInvalidate]; + [self setNeedsLayout]; else if ([keyPath isEqualToString:@"contentInset"]) - [self layoutInvalidate]; + [self setNeedsLayout]; else if ([keyPath isEqualToString:@"contentOffset"]) { - [self updatePosition]; - - if (!self.isAlwaysVisible) + if ([object isEqual:self.superview]) + [self updatePosition]; + + if (!self.isShowHideOnScroll || + (_observedScrollView && ![object isEqual:_observedScrollView]) || + (!_observedScrollView && ![object isEqual:self.superview])) + return; + + UIScrollView *scrollView = (UIScrollView *)object; + + if (self.isDisableShowHideOnScrollIfContentSizeLessThenFrame && + scrollView.contentSize.height <= scrollView.frame.size.height-(scrollView.contentInset.top+scrollView.contentInset.bottom)) + return; + + CGPoint newOffset = [[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]; + + CGFloat offsetY = newOffset.y; + CGFloat tempDiff = self.tempOffsetY - offsetY; + + if ((self.tempDiff > 0.f && tempDiff < 0.f) || (self.tempDiff < 0.f && tempDiff > 0.f) || self.tempDiff == 0.f) { - UIScrollView *scrollView = (UIScrollView *)_parentView; - - CGPoint newOffset = [[change valueForKey:NSKeyValueChangeNewKey] CGPointValue]; - - CGFloat offsetY = newOffset.y; - CGFloat tempDiff = self.tempOffsetY - offsetY; - - if ((self.tempDiff > 0.f && tempDiff < 0.f) || (self.tempDiff < 0.f && tempDiff > 0.f) || self.tempDiff == 0.f) - { - self.offsetY = offsetY; - self.tempDiff = tempDiff; - } - else + self.offsetY = offsetY; + self.tempDiff = tempDiff; + } + else + { + CGFloat diff = self.offsetY - offsetY; + + if (scrollView.isTracking && scrollView.isDragging && (diff > _scrollSensitivity || diff < -_scrollSensitivity)) { - CGFloat diff = self.offsetY - offsetY; - - if (scrollView.isTracking && scrollView.isDragging && (diff > _scrollSensitivity || diff < -_scrollSensitivity)) - { - if (self.offsetY > offsetY) - [self showAnimated:YES completionHandler:nil]; - else - [self hideAnimated:YES completionHandler:^(void) - { - if (self.isHideButtonsOnScroll) - [self hideButtonsAnimated:NO completionHandler:nil]; - }]; - } + if (self.offsetY > offsetY) + [self showAnimated:YES completionHandler:nil]; + else + [self hideAnimated:YES completionHandler:^(void) + { + if (self.isHideButtonsOnScroll) + [self hideButtonsAnimated:NO completionHandler:nil]; + }]; } - - if (offsetY >= -scrollView.contentInset.top && - offsetY < scrollView.contentSize.height-scrollView.frame.size.height+scrollView.contentInset.bottom) - self.tempOffsetY = offsetY; } + + if (offsetY >= -scrollView.contentInset.top && + offsetY < scrollView.contentSize.height-scrollView.frame.size.height+scrollView.contentInset.bottom) + self.tempOffsetY = offsetY; + } + else if ([keyPath isEqualToString:@"contentSize"]) + { + // } else [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } +#pragma mark - + +- (void)setObservedScrollView:(UIScrollView *)observedScrollView +{ + if (observedScrollView) + NSAssert([observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); + + if (self.isObserversForScrollViewAdded) + { + [_observedScrollView removeObserver:self forKeyPath:@"contentInset"]; + [_observedScrollView removeObserver:self forKeyPath:@"contentOffset"]; + [_observedScrollView removeObserver:self forKeyPath:@"contentSize"]; + } + + if (observedScrollView) + { + _observersForScrollViewAdded = YES; + + [observedScrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; + [observedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + [observedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; + } + else _observersForScrollViewAdded = NO; + + _observedScrollView = observedScrollView; +} + #pragma mark - Support + (void)animateStandardWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay animations:(void(^)())animations completion:(void(^)(BOOL finished))completion diff --git a/LGPlusButtonsView/LGPlusButtonsViewShared.h b/LGPlusButtonsView/LGPlusButtonsViewShared.h new file mode 100644 index 0000000..f1dd40f --- /dev/null +++ b/LGPlusButtonsView/LGPlusButtonsViewShared.h @@ -0,0 +1,42 @@ +// +// LGPlusButtonsViewShared.h +// LGPlusButtonsView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGPlusButtonsView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import +#import "LGPlusButtonsView.h" + +#define kLGPlusButtonsViewMargin 4.f + +@interface LGPlusButtonsViewShared : NSObject + ++ (NSString *)stringFromOrientation:(LGPlusButtonsViewOrientation)orientation; ++ (NSString *)stringFromState:(UIControlState)state; ++ (NSString *)stringFromState:(UIControlState)state andOrientation:(LGPlusButtonsViewOrientation)orientation; ++ (UIImage *)image1x1WithColor:(UIColor *)color; + +@end diff --git a/LGPlusButtonsView/LGPlusButtonsViewShared.m b/LGPlusButtonsView/LGPlusButtonsViewShared.m new file mode 100644 index 0000000..1c44abc --- /dev/null +++ b/LGPlusButtonsView/LGPlusButtonsViewShared.m @@ -0,0 +1,66 @@ +// +// LGPlusButtonsViewShared.m +// LGPlusButtonsView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGPlusButtonsView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import "LGPlusButtonsViewShared.h" + +@implementation LGPlusButtonsViewShared + ++ (NSString *)stringFromOrientation:(LGPlusButtonsViewOrientation)orientation +{ + return [NSString stringWithFormat:@"%lu", (long unsigned)orientation]; +} + ++ (NSString *)stringFromState:(UIControlState)state +{ + return [NSString stringWithFormat:@"%lu", (long unsigned)state]; +} + ++ (NSString *)stringFromState:(UIControlState)state andOrientation:(LGPlusButtonsViewOrientation)orientation +{ + return [NSString stringWithFormat:@"%lu_%lu", (long unsigned)state, (long unsigned)orientation]; +} + ++ (UIImage *)image1x1WithColor:(UIColor *)color +{ + CGRect rect = CGRectMake(0.f, 0.f, 1.f, 1.f); + + UIGraphicsBeginImageContext(rect.size); + + CGContextRef context = UIGraphicsGetCurrentContext(); + + CGContextSetFillColorWithColor(context, color.CGColor); + CGContextFillRect(context, rect); + + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return image; +} + +@end diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 95fa1fd..4d8d50b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ CocoaPods is a dependency manager for Objective-C, which automates and simplifie #### Podfile ```ruby platform :ios, '6.0' -pod 'LGPlusButtonsView', '~> 1.0.0' +pod 'LGPlusButtonsView', '~> 1.1.0' ``` ### With Carthage @@ -31,7 +31,7 @@ Carthage is a lightweight dependency manager for Swift and Objective-C. It lever #### Cartfile ``` -github "Friend-LGA/LGPlusButtonsView" ~> 1.0.0 +github "Friend-LGA/LGPlusButtonsView" ~> 1.1.0 ``` ## Usage @@ -47,31 +47,59 @@ In the source files where you need to use the library, import the header file: You have several methods for initialization: ```objective-c -- (instancetype)initWithView:(UIView *)view - numberOfButtons:(NSUInteger)numberOfButtons - showsPlusButton:(BOOL)showsPlusButton; +- (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons + firstButtonIsPlusButton:(BOOL)firstButtonIsPlusButton + showAfterInit:(BOOL)showAfterInit; ``` More init methods you can find in [LGPlusButtonsView.h](https://github.com/Friend-LGA/LGPlusButtonsView/blob/master/LGPlusButtonsView/LGPlusButtonsView.h) ### Handle actions -To handle actions you can use initialization methods with blocks or delegate, or implement it after initialization. +To handle actions you can use blocks, delegate, or notifications: #### Delegate ```objective-c @property (assign, nonatomic) id delegate; +- (void)plusButtonsViewWillShow:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillHide:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidShow:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidHide:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillShowButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewWillHideButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidShowButtons:(LGPlusButtonsView *)plusButtonsView; +- (void)plusButtonsViewDidHideButtons:(LGPlusButtonsView *)plusButtonsView; - (void)plusButtonsView:(LGPlusButtonsView *)plusButtonsView buttonPressedWithTitle:(NSString *)title description:(NSString *)description index:(NSUInteger)index; -- (void)plusButtonsViewPlusButtonPressed:(LGPlusButtonsView *)plusButtonsView; ``` #### Blocks ```objective-c +@property (strong, nonatomic) void (^willShowHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^willHideHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^didShowHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^didHideHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^willShowButtonsHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^willHideButtonsHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^didShowButtonsHandler)(LGPlusButtonsView *plusButtonView); +@property (strong, nonatomic) void (^didHideButtonsHandler)(LGPlusButtonsView *plusButtonView); @property (strong, nonatomic) void (^actionHandler)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index); -@property (strong, nonatomic) void (^plusButtonActionHandler)(LGPlusButtonsView *plusButtonView); +``` + +#### Notifications + +```objective-c +kLGPlusButtonsViewWillShowNotification; +kLGPlusButtonsViewWillHideNotification; +kLGPlusButtonsViewDidShowNotification; +kLGPlusButtonsViewDidHideNotification; +kLGPlusButtonsViewWillShowButtonsNotification; +kLGPlusButtonsViewWillHideButtonsNotification; +kLGPlusButtonsViewDidShowButtonsNotification; +kLGPlusButtonsViewDidHideButtonsNotification; +kLGPlusButtonsViewActionNotification; ``` ### More