Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TWViewController

  • Loading branch information...
commit d78a50c9f5653015a65ced74e8b2497003df5407 1 parent 00d093e
@soffes soffes authored
View
2  Readme.markdown
@@ -6,6 +6,7 @@ TWToolkit makes life easier. It is made up of various view controllers, views, a
### View Controllers
+* [TWViewController][] - custom modal craziness
* [TWPickerViewController][] - easily create picker view controllers like the Settings app
* [TWMessagesViewController][] - simple message UI like the built-in SMS app
@@ -68,6 +69,7 @@ You can also import individual files instead of the whole framework (for faster
* [Future features](http://github.com/tastefulworks/twtoolkit/issues/labels/Enhancement)
[Tasteful Works]: http://tastefulworks.com/
+[TWViewController]: http://github.com/tastefulworks/twtoolkit/blob/master/TWToolkit/TWViewController.h
[TWPickerViewController]: http://github.com/tastefulworks/twtoolkit/blob/master/TWToolkit/TWPickerViewController.h
[TWMessagesViewController]: http://github.com/tastefulworks/twtoolkit/blob/master/TWToolkit/TWMessagesViewController.h
[TWHUDView]: http://github.com/tastefulworks/twtoolkit/blob/master/TWToolkit/TWHUDView.h
View
BIN  Resources/TWToolkit.bundle/images/vignette-ipad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 TWToolkit.xcodeproj/project.pbxproj
@@ -31,6 +31,9 @@
B253C1FB10728DC500E0CE10 /* TWHUDView.m in Sources */ = {isa = PBXBuildFile; fileRef = B253C1F910728DC500E0CE10 /* TWHUDView.m */; };
B25E614011CFBA34001DA5CD /* UIViewController+displayError.h in Headers */ = {isa = PBXBuildFile; fileRef = B25E613E11CFBA34001DA5CD /* UIViewController+displayError.h */; };
B25E614111CFBA34001DA5CD /* UIViewController+displayError.m in Sources */ = {isa = PBXBuildFile; fileRef = B25E613F11CFBA34001DA5CD /* UIViewController+displayError.m */; };
+ B26AAC2411EE90F2006BB929 /* TWModalViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B26AAC2111EE90F2006BB929 /* TWModalViewController.h */; };
+ B26AAC2511EE90F2006BB929 /* TWViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B26AAC2211EE90F2006BB929 /* TWViewController.h */; };
+ B26AAC2611EE90F2006BB929 /* TWViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B26AAC2311EE90F2006BB929 /* TWViewController.m */; };
B270B5EE117C9EDC00944B8A /* UIColor+alpha.h in Headers */ = {isa = PBXBuildFile; fileRef = B270B5EC117C9EDC00944B8A /* UIColor+alpha.h */; };
B270B5EF117C9EDC00944B8A /* UIColor+alpha.m in Sources */ = {isa = PBXBuildFile; fileRef = B270B5ED117C9EDC00944B8A /* UIColor+alpha.m */; };
B27E357D11815C7F006A3499 /* TWCategories.h in Headers */ = {isa = PBXBuildFile; fileRef = B27E357A11815C7F006A3499 /* TWCategories.h */; };
@@ -106,6 +109,9 @@
B253C1F910728DC500E0CE10 /* TWHUDView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TWHUDView.m; sourceTree = "<group>"; };
B25E613E11CFBA34001DA5CD /* UIViewController+displayError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+displayError.h"; sourceTree = "<group>"; };
B25E613F11CFBA34001DA5CD /* UIViewController+displayError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+displayError.m"; sourceTree = "<group>"; };
+ B26AAC2111EE90F2006BB929 /* TWModalViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TWModalViewController.h; sourceTree = "<group>"; };
+ B26AAC2211EE90F2006BB929 /* TWViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TWViewController.h; sourceTree = "<group>"; };
+ B26AAC2311EE90F2006BB929 /* TWViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TWViewController.m; sourceTree = "<group>"; };
B270B5EC117C9EDC00944B8A /* UIColor+alpha.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+alpha.h"; sourceTree = "<group>"; };
B270B5ED117C9EDC00944B8A /* UIColor+alpha.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+alpha.m"; sourceTree = "<group>"; };
B27E357A11815C7F006A3499 /* TWCategories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TWCategories.h; sourceTree = "<group>"; };
@@ -246,6 +252,9 @@
B28517D51063E42A008D42E7 /* View Controllers */ = {
isa = PBXGroup;
children = (
+ B26AAC2111EE90F2006BB929 /* TWModalViewController.h */,
+ B26AAC2211EE90F2006BB929 /* TWViewController.h */,
+ B26AAC2311EE90F2006BB929 /* TWViewController.m */,
B28517D81063E43E008D42E7 /* TWPickerViewController.h */,
B28517D91063E43E008D42E7 /* TWPickerViewController.m */,
B2C6829F114954DF006EDD71 /* TWMessagesViewController.h */,
@@ -405,6 +414,8 @@
B2D393CB11E4CCE4002B0948 /* NSDate+ISO8601String.h in Headers */,
B2869DEA11EBB935006910B9 /* TWLabel.h in Headers */,
B2E3050011EC300100E7A6FB /* TWIndicatorLabel.h in Headers */,
+ B26AAC2411EE90F2006BB929 /* TWModalViewController.h in Headers */,
+ B26AAC2511EE90F2006BB929 /* TWViewController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -486,6 +497,7 @@
B2D393CC11E4CCE4002B0948 /* NSDate+ISO8601String.m in Sources */,
B2869DEB11EBB935006910B9 /* TWLabel.m in Sources */,
B2E3050111EC300100E7A6FB /* TWIndicatorLabel.m in Sources */,
+ B26AAC2611EE90F2006BB929 /* TWViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
19 TWToolkit/TWModalViewController.h
@@ -0,0 +1,19 @@
+//
+// TWModalViewController.h
+// TWToolkit
+//
+// Created by Sam Soffes on 7/14/10.
+// Copyright 2010 Tasteful Works. All rights reserved.
+//
+
+@class TWViewController;
+
+@protocol TWModalViewController <NSObject, NSCoding>
+
+@required
+
+@property (nonatomic, assign) TWViewController *modalParentViewController;
+
+- (UIView *)view;
+
+@end
View
2  TWToolkit/TWToolkit.h
@@ -9,6 +9,8 @@
// View Controllers
#import <TWToolkit/TWPickerViewController.h>
#import <TWToolkit/TWMessagesViewController.h>
+#import <TWToolkit/TWViewController.h>
+#import <TWToolkit/TWModalViewController.h>
// Views
#import <TWToolkit/TWGradientView.h>
View
32 TWToolkit/TWViewController.h
@@ -0,0 +1,32 @@
+//
+// TWViewController.h
+// TWToolkit
+//
+// Created by Sam Soffes on 7/14/10.
+// Copyright 2010 Tasteful Works. All rights reserved.
+//
+// TODO: Support iPhone and iPhone 4
+//
+
+#import "TWModalViewController.h"
+
+@interface TWViewController : UIViewController <TWModalViewController> {
+
+ TWViewController *_modalParentViewController;
+
+ id<TWModalViewController> _customModalViewController;
+ UIView *_modalContainerView;
+ UIImageView *_modalContainerBackgroundView;
+ UIImageView *_vignetteView;
+}
+
+@property (nonatomic, assign) TWViewController *modalParentViewController;
+@property (nonatomic, retain, readonly) UIViewController *customModalViewController;
+
+- (void)layoutViews;
+- (void)layoutViewsWithOrientation:(UIInterfaceOrientation)orientation;
+
+- (void)presentCustomModalViewController:(id<TWModalViewController>)viewController;
+- (void)dismissCustomModalViewController;
+
+@end
View
150 TWToolkit/TWViewController.m
@@ -0,0 +1,150 @@
+//
+// TWViewController.m
+// TWToolkit
+//
+// Created by Sam Soffes on 7/14/10.
+// Copyright 2010 Tasteful Works. All rights reserved.
+//
+
+#import "TWViewController.h"
+#import "UIImage+BundleImage.h"
+#import "UIView+fading.h"
+#import <QuartzCore/QuartzCore.h>
+
+@implementation TWViewController
+
+@synthesize modalParentViewController = _modalParentViewController;
+@synthesize customModalViewController = _customModalViewController;
+
+#pragma mark NSObject
+
+- (void)dealloc {
+ [_customModalViewController release];
+ [_modalContainerView release];
+ [_modalContainerBackgroundView release];
+ [_vignetteView release];
+ [super dealloc];
+}
+
+#pragma mark UIViewController
+
+- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
+ [UIView beginAnimations:@"rotate" context:self];
+ [UIView setAnimationDuration:duration];
+ [self layoutViewsWithOrientation:toInterfaceOrientation];
+ [UIView commitAnimations];
+}
+
+#pragma mark Layout
+
+- (void)layoutViews {
+ [self layoutViewsWithOrientation:self.interfaceOrientation];
+}
+
+
+- (void)layoutViewsWithOrientation:(UIInterfaceOrientation)orientation {
+ CGSize size;
+
+ // Landscape
+ if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
+ size = CGSizeMake(1024.0, 768.0);
+ _vignetteView.frame = CGRectMake(0.0, -128.0, 1024.0, 1024.0);
+ }
+
+ // Portrait
+ else {
+ size = CGSizeMake(768.0, 1024.0);
+ _vignetteView.frame = CGRectMake(-128.0, 0.0, 1024.0, 1024.0);
+ }
+
+ _modalContainerBackgroundView.frame = CGRectMake(roundf(size.width - 554.0) / 2.0, (roundf(size.height - 634.0) / 2.0), 554.0, 634.0);
+}
+
+#pragma mark Modal
+
+- (void)presentCustomModalViewController:(id<TWModalViewController>)viewController {
+ _customModalViewController = [viewController retain];
+
+ if (_customModalViewController == nil) {
+ return;
+ }
+
+ _customModalViewController.modalParentViewController = self;
+
+ if (_vignetteView == nil) {
+ _vignetteView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"images/vignette-ipad.png" bundle:@"TWToolkit.bundle"]];
+ _vignetteView.alpha = 0.0;
+ }
+
+ [self.view addSubview:_vignetteView];
+ [_vignetteView fadeIn];
+
+ if (_modalContainerBackgroundView == nil) {
+ _modalContainerBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"form-background.png"]];
+ _modalContainerBackgroundView.autoresizesSubviews = NO;
+ _modalContainerBackgroundView.userInteractionEnabled = YES;
+ }
+
+ [self.view addSubview:_modalContainerBackgroundView];
+
+ if (_modalContainerView == nil) {
+ _modalContainerView = [[UIView alloc] initWithFrame:CGRectMake(7.0, 7.0, 540.0, 620.0)];
+ _modalContainerView.layer.cornerRadius = 5.0;
+ _modalContainerView.clipsToBounds = YES;
+ [_modalContainerBackgroundView addSubview:_modalContainerView];
+ }
+
+ UIView *modalView = _customModalViewController.view;
+ [_modalContainerView addSubview:modalView];
+ modalView.frame = CGRectMake(0.0, 0.0, 540.0, 620.0);
+
+ CGSize size;
+ if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
+ size = CGSizeMake(1024.0, 768.0);
+ } else {
+ size = CGSizeMake(768.0, 1024.0);
+ }
+
+ _modalContainerBackgroundView.frame = CGRectMake(roundf(size.width - 554.0) / 2.0, (roundf(size.height - 634.0) / 2.0) + size.height, 554.0, 634.0);
+
+ [UIView beginAnimations:@"presentModal" context:nil];
+ [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
+ [UIView setAnimationDuration:0.5];
+ [self layoutViewsWithOrientation:self.interfaceOrientation];
+ [UIView commitAnimations];
+}
+
+
+- (void)dismissCustomModalViewController {
+ CGSize size;
+ if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
+ size = CGSizeMake(1024.0, 768.0);
+ } else {
+ size = CGSizeMake(768.0, 1024.0);
+ }
+
+ [UIView beginAnimations:@"dismissModal" context:nil];
+ [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
+ [UIView setAnimationDuration:0.4];
+ _modalContainerBackgroundView.frame = CGRectMake(roundf(size.width - 554.0) / 2.0, (roundf(size.height - 634.0) / 2.0) + size.height, 554.0, 634.0);
+ [UIView commitAnimations];
+
+ [_modalContainerBackgroundView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.5];
+
+ [UIView beginAnimations:@"removeVignette" context:nil];
+ [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
+ [UIView setAnimationDelay:0.2];
+ _vignetteView.alpha = 0.0;
+ [UIView commitAnimations];
+ [_vignetteView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.6];
+
+ _customModalViewController = nil;
+
+ [_modalContainerView release];
+ _modalContainerView = nil;
+
+ [_modalContainerBackgroundView release];
+ _modalContainerBackgroundView = nil;
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.