Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support auto rotation and auto resize for alert and action sheets #38

Closed
wants to merge 5 commits into from

4 participants

@siuying

This patch add support of BlocksAlertsAnd-ActionSheets for different orientation and auto resize.

Instead of current approach that use UIWindow, this patch change the BlockBackground such that it is a UIView that is added to the first key window first subview.

siuying added some commits
@gpambrozio
Owner

Does it still work when a keyboard is shown? The whole idea of using UIWindow is because of the keyboard.

@bencallis

Just tested and sadly there are issues with the text prompt.

@tcunning

Wouldn't the other issue with this approach be the nav bar wouldn't be covered by the alert view.

@siuying

@gpambrozio Yes, i can confirm this. It seems need to handle rotation with others way.

@siuying siuying closed this
@siuying

@tcunning I was not aware there are already another PR (#36) on this. Look like it fullfill my needs already :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. @siuying
  2. @siuying

    Make the BlockActionSheet and BlockAlertView rotate based on UIWindow…

    siuying authored
    … rotation
    
    - instead of use a UIWindow, use a UIView as background, and add it as a subview of first subview of key window
    - enable auto resize background
  3. @siuying
  4. @siuying

    remove unused code

    siuying authored
  5. @siuying

    remove unused line

    siuying authored
This page is out of date. Refresh to see the latest.
View
1  BlockAlertsDemo/BlockAlertsDemo-Info.plist
@@ -35,6 +35,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
</dict>
</plist>
View
2  BlockAlertsDemo/BlockAlertsDemoViewController.m
@@ -19,7 +19,7 @@ @implementation BlockAlertsDemoViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
+ return YES;
}
- (IBAction)showAlert:(id)sender
View
10 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m
@@ -38,10 +38,12 @@ - (id)initWithTitle:(NSString *)title
{
if ((self = [super init]))
{
- UIWindow *parentView = [BlockBackground sharedInstance];
+ UIView *parentView = [BlockBackground sharedInstance];
CGRect frame = parentView.bounds;
_view = [[UIView alloc] initWithFrame:frame];
+ _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
+
_blocks = [[NSMutableArray alloc] init];
_height = kActionSheetTopMargin;
@@ -52,6 +54,7 @@ - (id)initWithTitle:(NSString *)title
lineBreakMode:UILineBreakModeWordWrap];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height, frame.size.width-kActionSheetBorder*2, size.height)];
+ labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
labelView.font = titleFont;
labelView.numberOfLines = 0;
labelView.lineBreakMode = UILineBreakModeWordWrap;
@@ -148,6 +151,7 @@ - (void)showInView:(UIView *)view
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight);
+ button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
button.titleLabel.font = buttonFont;
button.titleLabel.minimumFontSize = 6;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
@@ -170,6 +174,7 @@ - (void)showInView:(UIView *)view
UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds];
modalBackground.image = background;
+ modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
modalBackground.contentMode = UIViewContentModeScaleToFill;
[_view insertSubview:modalBackground atIndex:0];
[modalBackground release];
@@ -180,7 +185,8 @@ - (void)showInView:(UIView *)view
frame.origin.y = [BlockBackground sharedInstance].bounds.size.height;
frame.size.height = _height + kActionSheetBounce;
_view.frame = frame;
-
+ _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
+
__block CGPoint center = _view.center;
center.y -= _height + kActionSheetBounce;
View
4 BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m
@@ -44,7 +44,7 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message
{
if ((self = [super init]))
{
- UIWindow *parentView = [BlockBackground sharedInstance];
+ UIView *parentView = [BlockBackground sharedInstance];
CGRect frame = parentView.bounds;
frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5);
frame.size.width = background.size.width;
@@ -251,7 +251,7 @@ - (void)show
frame.origin.y = - _height;
frame.size.height = _height;
_view.frame = frame;
-
+ _view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds];
modalBackground.image = background;
modalBackground.contentMode = UIViewContentModeScaleToFill;
View
4 BlockAlertsDemo/ToAddToYourProjects/BlockBackground.h
@@ -8,9 +8,7 @@
#import <UIKit/UIKit.h>
-@interface BlockBackground : UIWindow {
-@private
- UIWindow *_previousKeyWindow;
+@interface BlockBackground : UIView {
}
+ (BlockBackground *) sharedInstance;
View
20 BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m
@@ -68,9 +68,9 @@ - (id)autorelease
- (id)init
{
- self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
+ self = [super initWithFrame:[[BlockBackground firstWindowSubview] bounds]];
if (self) {
- self.windowLevel = UIWindowLevelStatusBar;
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.hidden = YES;
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f];
@@ -83,11 +83,9 @@ - (void)addToMainWindow:(UIView *)view
{
if (self.hidden)
{
- _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain];
self.alpha = 0.0f;
self.hidden = NO;
self.userInteractionEnabled = YES;
- [self makeKeyWindow];
}
if (self.subviews.count > 0)
@@ -105,8 +103,9 @@ - (void)addToMainWindow:(UIView *)view
[_backgroundImage release];
_backgroundImage = nil;
}
-
+
[self addSubview:view];
+ [[BlockBackground firstWindowSubview] addSubview:self];
}
- (void)reduceAlphaIfEmpty
@@ -132,9 +131,6 @@ - (void)removeView:(UIView *)view
if (self.subviews.count == 0)
{
self.hidden = YES;
- [_previousKeyWindow makeKeyWindow];
- [_previousKeyWindow release];
- _previousKeyWindow = nil;
}
else
{
@@ -160,4 +156,12 @@ - (void)drawRect:(CGRect)rect
CGGradientRelease(gradient);
}
++(UIView*) firstWindowSubview {
+ UIWindow* window = [UIApplication sharedApplication].keyWindow;
+ if (!window) {
+ window = [[UIApplication sharedApplication].windows objectAtIndex:0];
+ }
+ return [[window subviews] objectAtIndex:0];
+}
+
@end
Something went wrong with that request. Please try again.