Skip to content
Browse files

animate progress

  • Loading branch information...
1 parent a77ab7e commit a2df786901993223b93cefaf45a8d891cca36ee0 Erik Aigner committed Apr 13, 2012
Showing with 35 additions and 10 deletions.
  1. +25 −10 CODialog.m
  2. +10 −0 CODialog/COViewController.m
View
35 CODialog.m
@@ -21,6 +21,7 @@ @interface CODialog ()
@property (nonatomic, strong) UIView *hostView;
@property (nonatomic, strong) CODialogWindowOverlay *overlayWindow;
@property (nonatomic, strong) UIView *contentView;
+@property (nonatomic, strong) UIView *accessoryView;
@property (nonatomic, strong) NSMutableArray *textFields;
@property (nonatomic, strong) NSMutableArray *buttons;
@property (nonatomic, strong) UIFont *titleFont;
@@ -50,11 +51,11 @@ @implementation CODialog {
Synth(dialogStyle)
Synth(title)
Synth(subtitle)
-Synth(progress)
Synth(batchDelay)
Synth(hostView)
Synth(overlayWindow)
Synth(contentView)
+Synth(accessoryView)
Synth(textFields)
Synth(buttons)
Synth(titleFont)
@@ -128,15 +129,29 @@ - (CGRect)defaultDialogFrame {
return insetFrame;
}
-- (UIView *)accessoryView {
+- (void)setProgress:(CGFloat)progress {
+ UIProgressView *view = (id)self.accessoryView;
+ if ([view isKindOfClass:[UIProgressView class]]) {
+ [view setProgress:progress animated:YES];
+ }
+}
+
+- (CGFloat)progress {
+ UIProgressView *view = (id)self.accessoryView;
+ if ([view isKindOfClass:[UIProgressView class]]) {
+ return view.progress;
+ }
+ return 0;
+}
+
+- (UIView *)makeAccessoryView {
if (self.dialogStyle == CODialogStyleIndeterminate) {
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityView startAnimating];
return activityView;
} else if (self.dialogStyle == CODialogStyleDeterminate) {
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
- progressView.progress = 0.5; // TODO: remove
progressView.frame = CGRectMake(0, 0, 200.0, 88.0);
return progressView;
@@ -188,18 +203,18 @@ - (void)layoutComponents {
layout.subtitleRect = CGRectMake(CGRectGetMinX(layoutFrame), minY, layoutWidth, subtitleHeight);
// Accessory frame (note that views are in the content view coordinate system)
- UIView *accessoryView = [self accessoryView];
- accessoryView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
+ self.accessoryView = [self makeAccessoryView];
+ self.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
CGFloat accessoryHeight = 0;
CGFloat accessoryWidth = CGRectGetWidth(layoutFrame);
CGFloat accessoryLeft = 0;
minY = CGRectGetMaxY(layout.subtitleRect) - layoutFrameInset;
- if (accessoryView != nil) {
- accessoryHeight = CGRectGetHeight(accessoryView.frame);
- accessoryWidth = CGRectGetWidth(accessoryView.frame);
+ if (self.accessoryView != nil) {
+ accessoryHeight = CGRectGetHeight(self.accessoryView.frame);
+ accessoryWidth = CGRectGetWidth(self.accessoryView.frame);
accessoryLeft = (CGRectGetWidth(layoutFrame) - accessoryWidth) / 2.0;
minY += kCODialogPadding;
}
@@ -233,9 +248,9 @@ - (void)layoutComponents {
newContentView.contentMode = UIViewContentModeRedraw;
// Layout accessory view
- accessoryView.frame = layout.accessoryRect;
+ self.accessoryView.frame = layout.accessoryRect;
- [newContentView addSubview:accessoryView];
+ [newContentView addSubview:self.accessoryView];
// Layout text fields
if (numTextFields > 0) {
View
10 CODialog/COViewController.m
@@ -27,9 +27,19 @@ - (void)viewDidAppear:(BOOL)animated {
// Display dialog
self.dialog = [CODialog dialogWithView:self.view];
+ [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(advanceProgress:) userInfo:nil repeats:YES];
+
[self showDefault:nil];
}
+- (void)advanceProgress:(NSTimer *)sender {
+ CGFloat progress = self.dialog.progress + 0.25;
+ if (progress > 1.0) {
+ progress = 0;
+ }
+ self.dialog.progress = progress;
+}
+
- (void)doNothing:(id)sender {
NSLog(@"i'm very good at doing nothing");
}

0 comments on commit a2df786

Please sign in to comment.
Something went wrong with that request. Please try again.