Skip to content

Commit

Permalink
Auto hide when the device rotated #35
Browse files Browse the repository at this point in the history
  • Loading branch information
iTofu committed Apr 26, 2017
1 parent 7197df0 commit 3338297
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Demo/LCActionSheetDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
TargetAttributes = {
76485D6D1D38CB51009DDCA1 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 4BZ2VM448J;
};
76485D861D38CB51009DDCA1 = {
CreatedOnToolsVersion = 7.3.1;
Expand Down Expand Up @@ -608,7 +609,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4BZ2VM448J;
INFOPLIST_FILE = LCActionSheetDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -623,7 +624,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4BZ2VM448J;
INFOPLIST_FILE = LCActionSheetDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
9 changes: 6 additions & 3 deletions Demo/LCActionSheetDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ - (IBAction)showCustomActionSheet {
// V 2.7.1+
actionSheet.separatorColor = [UIColor orangeColor];

// V 3.1.0+
actionSheet.autoHideWhenDeviceRotated = YES;

[actionSheet show];
}

Expand Down Expand Up @@ -92,11 +95,11 @@ - (IBAction)showBlockActionSheet {

// Append buttons methods
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
// [actionSheet appendButtonWithTitle:@"WoW" atIndex:1];
// [actionSheet appendButtonWithTitle:@"WoW" atIndex:7];

NSMutableIndexSet *set = [[NSMutableIndexSet alloc] init];
[set addIndex:7];
[set addIndex:8];
[set addIndex:1];
[set addIndex:2];
[actionSheet appendButtonsWithTitles:@[@"Hello", @"World"] atIndexes:set];
});
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/LCActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ typedef void(^LCActionSheetDidDismissHandler)(LCActionSheet *actionSheet, NSUInt
*/
@property (nonatomic, strong) UIColor *separatorColor;

/**
Auto hide when the device rotated. Default is NO, won't auto hides.
*/
@property (nonatomic, assign) BOOL autoHideWhenDeviceRotated;


/**
LCActionSheet clicked handler.
Expand Down
17 changes: 8 additions & 9 deletions Sources/LCActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,17 @@ - (instancetype)config:(LCActionSheetConfig *)config {
_blurEffectStyle = config.blurEffectStyle;
_titleEdgeInsets = config.titleEdgeInsets;
_separatorColor = config.separatorColor;
_autoHideWhenDeviceRotated = config.autoHideWhenDeviceRotated;

return self;
}

- (void)setupView {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidChangeStatusBarOrientation)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(handleDidChangeStatusBarOrientation)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow addSubview:self];
Expand Down Expand Up @@ -412,11 +414,8 @@ - (void)appendButtonsWithTitles:(NSArray<NSString *> *)titles atIndexes:(NSIndex
}

- (void)handleDidChangeStatusBarOrientation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) {
self.blurEffectView.contentMode = UIViewContentModeScaleAspectFill;
} else {
self.blurEffectView.contentMode = UIViewContentModeBottom;
if (self.autoHideWhenDeviceRotated) {
[self hideWithButtonIndex:self.cancelButtonIndex];
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/LCActionSheetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong) UIColor *separatorColor;

/**
Auto hide when the device rotated. Default is NO, won't auto hides.
*/
@property (nonatomic, assign) BOOL autoHideWhenDeviceRotated;


/**
LCActionSheetConfig instance.
Expand Down

0 comments on commit 3338297

Please sign in to comment.