Skip to content
This repository

add more position to show #11

Closed
wants to merge 2 commits into from

2 participants

curer Barrett Jacobsen
curer

easy user on iPad

Barrett Jacobsen
Collaborator

This pull request is a year old and can no longer be auto-merged so I'm closing it to get a fresh start. Feel free to rebase submit a new pull request.

Barrett Jacobsen barrettj closed this April 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Mar 08, 2012
curer add alertView animation position
easy user on iPad
deada9b
Mar 23, 2012
curer Orientation 431de01
This page is out of date. Refresh to see the latest.
2  .gitignore
... ...
@@ -1,2 +1,4 @@
1 1
 BlockAlertsDemo.xcodeproj/project.xcworkspace
2 2
 BlockAlertsDemo.xcodeproj/xcuserdata
  3
+
  4
+.DS_Store
2  BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h 100755 → 100644
@@ -21,6 +21,8 @@
21 21
 - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block;
22 22
 
23 23
 - (void)show;
  24
+- (void)showTo:(CGPoint )endPos andFromTop:(BOOL)bTop;
  25
+- (void)showFrom:(CGPoint )startPos toPos:(CGPoint)endPos andFromTop:(BOOL)bTop;
24 26
 - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
25 27
 
26 28
 @property (nonatomic, retain) UIImage *backgroundImage;
139  BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m 100755 → 100644
@@ -138,7 +138,61 @@ - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block
138 138
     [self addButtonWithTitle:title color:@"red" block:block];
139 139
 }
140 140
 
141  
-- (void)show
  141
+- (void)showDefaultStyle
  142
+{
  143
+    __block CGPoint center = _view.center;
  144
+    center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce;
  145
+    
  146
+    [UIView animateWithDuration:0.4
  147
+                          delay:0.0
  148
+                        options:UIViewAnimationCurveEaseOut
  149
+                     animations:^{
  150
+                         [BlockBackground sharedInstance].alpha = 1.0f;
  151
+                         _view.center = center;
  152
+                     } 
  153
+                     completion:^(BOOL finished) {
  154
+                         [UIView animateWithDuration:0.1
  155
+                                               delay:0.0
  156
+                                             options:0
  157
+                                          animations:^{
  158
+                                              center.y -= kAlertViewBounce;
  159
+                                              _view.center = center;
  160
+                                          } 
  161
+                                          completion:nil];
  162
+                     }];
  163
+}
  164
+
  165
+- (void)showStyleLeftRoRight
  166
+{
  167
+    CGRect frame = _view.frame;
  168
+    frame.origin.y +=  _height * 2;
  169
+    frame.size.height = _height;
  170
+    frame.origin.x  = -frame.size.width;
  171
+    _view.frame = frame;
  172
+    
  173
+    __block CGPoint center = _view.center;
  174
+    center.x = floorf([BlockBackground sharedInstance].bounds.size.width * 0.5) + kAlertViewBounce;
  175
+    
  176
+    [UIView animateWithDuration:0.4
  177
+                          delay:0.0
  178
+                        options:UIViewAnimationCurveEaseOut
  179
+                     animations:^{
  180
+                         [BlockBackground sharedInstance].alpha = 1.0f;
  181
+                         _view.center = center;
  182
+                     } 
  183
+                     completion:^(BOOL finished) {
  184
+                         [UIView animateWithDuration:0.1
  185
+                                               delay:0.0
  186
+                                             options:0
  187
+                                          animations:^{
  188
+                                              center.x -= kAlertViewBounce;
  189
+                                              _view.center = center;
  190
+                                          } 
  191
+                                          completion:nil];
  192
+                     }];
  193
+}
  194
+
  195
+- (void)setControl
142 196
 {
143 197
     BOOL isSecondButton = NO;
144 198
     NSUInteger index = 0;
@@ -147,7 +201,7 @@ - (void)show
147 201
         NSArray *block = [_blocks objectAtIndex:i];
148 202
         NSString *title = [block objectAtIndex:1];
149 203
         NSString *color = [block objectAtIndex:2];
150  
-
  204
+        
151 205
         UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]];
152 206
         image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width+1)>>1 topCapHeight:0];
153 207
         
@@ -197,7 +251,7 @@ - (void)show
197 251
                                actualFontSize:nil
198 252
                                      forWidth:_view.bounds.size.width-kAlertViewBorder*2 
199 253
                                 lineBreakMode:UILineBreakModeClip];
200  
-
  254
+            
201 255
             size.width = MAX(size.width, 80);
202 256
             if (size.width + 2 * kAlertViewBorder < width)
203 257
             {
@@ -246,7 +300,7 @@ - (void)show
246 300
             btn.frame = frame;
247 301
         }
248 302
     }
249  
-
  303
+    
250 304
     CGRect frame = _view.frame;
251 305
     frame.origin.y = - _height;
252 306
     frame.size.height = _height;
@@ -266,9 +320,73 @@ - (void)show
266 320
     }
267 321
     [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground;
268 322
     [[BlockBackground sharedInstance] addToMainWindow:_view];
  323
+}
269 324
 
270  
-    __block CGPoint center = _view.center;
271  
-    center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce;
  325
+- (void)show
  326
+{
  327
+    CGPoint pt = CGPointMake([BlockBackground sharedInstance].bounds.size.width / 2, 
  328
+                             [BlockBackground sharedInstance].bounds.size.height / 2);
  329
+    
  330
+    CGPoint start = CGPointMake([BlockBackground sharedInstance].bounds.size.width / 2, 
  331
+                                0);
  332
+    
  333
+    [self showFrom:start toPos:pt andFromTop:YES];
  334
+}
  335
+
  336
+- (void)showTo:(CGPoint )endPos andFromTop:(BOOL)bTop
  337
+{
  338
+    CGPoint startPoint = CGPointMake(0, 0);
  339
+    if (bTop) {
  340
+        startPoint.y = floorf([BlockBackground sharedInstance].bounds.size.height* 0.5) + kAlertViewBounce;
  341
+        startPoint.x = endPos.x;
  342
+    }
  343
+    else {
  344
+        startPoint.x = floorf([BlockBackground sharedInstance].bounds.size.width * 0.5) + kAlertViewBounce;
  345
+        startPoint.y = endPos.y;
  346
+    }
  347
+    
  348
+    [self showFrom:startPoint toPos:endPos andFromTop:bTop];
  349
+}
  350
+
  351
+- (void)showFrom:(CGPoint )startPos toPos:(CGPoint)endPos andFromTop:(BOOL)bTop
  352
+{
  353
+    [self setControl];
  354
+    
  355
+    BOOL bAnimatedToDown = YES;
  356
+    if (bTop) {
  357
+        bAnimatedToDown = (endPos.y > startPos.y);
  358
+    }
  359
+    else {
  360
+        bAnimatedToDown = (endPos.x > startPos.x);
  361
+    }
  362
+    
  363
+    CGSize size = _view.bounds.size;
  364
+    
  365
+    __block CGPoint center = startPos;
  366
+    
  367
+    int minX = size.width / 2 + kAlertViewBounce;
  368
+    int minY = size.height / 2 + kAlertViewBounce;
  369
+    int maxX = [BlockBackground sharedInstance].bounds.size.width - minX;
  370
+    int maxY = [BlockBackground sharedInstance].bounds.size.height - minY;
  371
+    
  372
+    center.x = MAX(center.x, minX);
  373
+    center.x = MIN(center.x, maxX);
  374
+    center.y = MAX(center.y, minY);
  375
+    center.y = MIN(center.y, maxY);
  376
+    
  377
+    _view.center = center;
  378
+    
  379
+    if (bTop) {
  380
+        center.y = floorf(bAnimatedToDown ? endPos.y + kAlertViewBounce : endPos.y - kAlertViewBounce);
  381
+    }
  382
+    else {
  383
+        center.x = floorf(bAnimatedToDown ? endPos.x + kAlertViewBounce : endPos.x - kAlertViewBounce);
  384
+    }
  385
+    
  386
+    center.x = MAX(center.x, minX);
  387
+    center.x = MIN(center.x, maxX);
  388
+    center.y = MAX(center.y, minY);
  389
+    center.y = MIN(center.y, maxY);
272 390
     
273 391
     [UIView animateWithDuration:0.4
274 392
                           delay:0.0
@@ -282,7 +400,14 @@ - (void)show
282 400
                                                delay:0.0
283 401
                                              options:0
284 402
                                           animations:^{
285  
-                                              center.y -= kAlertViewBounce;
  403
+                                              
  404
+                                              if (bTop) {
  405
+                                                  center.y -= bAnimatedToDown ? kAlertViewBounce : -kAlertViewBounce;
  406
+                                              }
  407
+                                              else {
  408
+                                                  center.x -= bAnimatedToDown ? kAlertViewBounce : -kAlertViewBounce;
  409
+                                              }
  410
+                                              
286 411
                                               _view.center = center;
287 412
                                           } 
288 413
                                           completion:nil];
61  BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m
@@ -75,12 +75,23 @@ - (id)init
75 75
         self.userInteractionEnabled = NO;
76 76
         self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f];
77 77
         self.vignetteBackground = NO;
  78
+        
  79
+	//
  80
+        [[NSNotificationCenter defaultCenter] addObserver:self 
  81
+                                                 selector:@selector(setRotation:) 
  82
+                                                     name:UIApplicationDidChangeStatusBarOrientationNotification	
  83
+                                                   object:nil];
  84
+        
  85
+        [self setRotation:nil];
  86
+
78 87
     }
79 88
     return self;
80 89
 }
81 90
 
82 91
 - (void)addToMainWindow:(UIView *)view
83 92
 {
  93
+    [self setRotation:nil];
  94
+    
84 95
     if (self.hidden)
85 96
     {
86 97
         _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain];
@@ -160,4 +171,54 @@ - (void)drawRect:(CGRect)rect
160 171
 	CGGradientRelease(gradient);
161 172
 }
162 173
 
  174
+- (void)setRotation:(NSNotification*)notification 
  175
+{
  176
+    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  177
+    
  178
+    CGRect orientationFrame = [UIScreen mainScreen].bounds;
  179
+    
  180
+    if(
  181
+       (UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) ||
  182
+       (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height)
  183
+       ) {
  184
+        float temp = orientationFrame.size.width;
  185
+        orientationFrame.size.width = orientationFrame.size.height;
  186
+        orientationFrame.size.height = temp;
  187
+    }
  188
+    
  189
+    self.transform = CGAffineTransformIdentity;
  190
+    self.frame = orientationFrame;    
  191
+    
  192
+    CGFloat posY = orientationFrame.size.height/2;
  193
+    CGFloat posX = orientationFrame.size.width/2;
  194
+    
  195
+    CGPoint newCenter;
  196
+    CGFloat rotateAngle;
  197
+    
  198
+    switch (orientation) { 
  199
+        case UIInterfaceOrientationPortraitUpsideDown:
  200
+            rotateAngle = M_PI; 
  201
+            newCenter = CGPointMake(posX, orientationFrame.size.height-posY);
  202
+            break;
  203
+        case UIInterfaceOrientationLandscapeLeft:
  204
+            rotateAngle = -M_PI/2.0f;
  205
+            newCenter = CGPointMake(posY, posX);
  206
+            break;
  207
+        case UIInterfaceOrientationLandscapeRight:
  208
+            rotateAngle = M_PI/2.0f;
  209
+            newCenter = CGPointMake(orientationFrame.size.height-posY, posX);
  210
+            break;
  211
+        default: // UIInterfaceOrientationPortrait
  212
+            rotateAngle = 0.0;
  213
+            newCenter = CGPointMake(posX, posY);
  214
+            break;
  215
+    }
  216
+    
  217
+    self.transform = CGAffineTransformMakeRotation(rotateAngle);
  218
+    self.center = newCenter;
  219
+    
  220
+    [self setNeedsLayout];
  221
+    [self layoutSubviews];
  222
+}
  223
+
163 224
 @end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.