From eef9cc818cb483f4e8a684bceb72b2b1fce40b4e Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Mon, 13 Apr 2015 14:07:49 +0200 Subject: [PATCH] Added the ability to hand over supportededInterfaceOrientations for CWStatusBarNotification. This is optional and the standard value is to support all masks. --- .../CWStatusBarNotification.h | 2 ++ .../CWStatusBarNotification.m | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CWStatusBarNotification/CWStatusBarNotification.h b/CWStatusBarNotification/CWStatusBarNotification.h index fcb4394..8dc8c31 100644 --- a/CWStatusBarNotification/CWStatusBarNotification.h +++ b/CWStatusBarNotification/CWStatusBarNotification.h @@ -22,6 +22,7 @@ typedef void(^CWCompletionBlock)(void); @interface CWViewController : UIViewController @property (nonatomic) UIStatusBarStyle preferredStatusBarStyle; +@property (nonatomic, setter=setSupportedInterfaceOrientations:) NSInteger supportedInterfaceOrientations; @end @interface CWStatusBarNotification : NSObject @@ -56,6 +57,7 @@ typedef NS_ENUM(NSInteger, CWNotificationAnimationType) { @property (copy, nonatomic) CWCompletionBlock notificationTappedBlock; @property (nonatomic) CWNotificationStyle notificationStyle; +@property (nonatomic) NSInteger supportedInterfaceOrientations; @property (nonatomic) CWNotificationAnimationStyle notificationAnimationInStyle; @property (nonatomic) CWNotificationAnimationStyle notificationAnimationOutStyle; @property (nonatomic) CWNotificationAnimationType notificationAnimationType; diff --git a/CWStatusBarNotification/CWStatusBarNotification.m b/CWStatusBarNotification/CWStatusBarNotification.m index 9163ede..4723d08 100644 --- a/CWStatusBarNotification/CWStatusBarNotification.m +++ b/CWStatusBarNotification/CWStatusBarNotification.m @@ -38,6 +38,12 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event @end +@interface CWViewController() + +@property (nonatomic, assign) NSInteger _cwViewControllerSupportedInterfaceOrientation; + +@end + @implementation CWViewController - (UIStatusBarStyle)preferredStatusBarStyle @@ -45,6 +51,16 @@ - (UIStatusBarStyle)preferredStatusBarStyle return _preferredStatusBarStyle; } +- (void)setSupportedInterfaceOrientations:(NSInteger)supportedInterfaceOrientations +{ + self._cwViewControllerSupportedInterfaceOrientation = supportedInterfaceOrientations; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + return self._cwViewControllerSupportedInterfaceOrientation; +} + @end # pragma mark - dispatch after with cancellation @@ -182,6 +198,7 @@ - (CWStatusBarNotification *)init self.notificationIsDismissing = NO; self.isCustomView = NO; self.preferredStatusBarStyle = UIStatusBarStyleDefault; + self.supportedInterfaceOrientations = UIInterfaceOrientationMaskAll; // create tap recognizer self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notificationTapped:)]; @@ -351,6 +368,7 @@ - (void)createNotificationWindow self.notificationWindow.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.notificationWindow.windowLevel = UIWindowLevelStatusBar; CWViewController *rootViewController = [[CWViewController alloc] init]; + [rootViewController setSupportedInterfaceOrientations:self.supportedInterfaceOrientations]; rootViewController.preferredStatusBarStyle = self.preferredStatusBarStyle; self.notificationWindow.rootViewController = rootViewController; self.notificationWindow.notificationHeight = [self getNotificationLabelHeight];