Skip to content

Commit

Permalink
Merge pull request kentnguyen#9 from lexrus/master
Browse files Browse the repository at this point in the history
Add a new method to resize semi-modal view (could use for handling text input)
  • Loading branch information
kentnguyen committed Aug 24, 2012
2 parents 38da8ad + 4789362 commit a724099
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 25 deletions.
Binary file modified Docs/ss2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions KNSemiModalViewControllerDemo.xcodeproj/project.pbxproj
Expand Up @@ -96,7 +96,9 @@
8B41C9711551561200413B5A /* Frameworks */,
8B41C96F1551561200413B5A /* Products */,
);
indentWidth = 2;
sourceTree = "<group>";
tabWidth = 2;
};
8B41C96F1551561200413B5A /* Products */ = {
isa = PBXGroup;
Expand Down
2 changes: 2 additions & 0 deletions KNSemiModalViewControllerDemo/KNThirdViewController.h
Expand Up @@ -12,7 +12,9 @@

@property (unsafe_unretained, nonatomic) IBOutlet UILabel *helpLabel;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *dismissButton;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *resizeButton;

- (IBAction)dismissButtonDidTouch:(id)sender;
- (IBAction)resizeSemiModalView:(id)sender;

@end
13 changes: 12 additions & 1 deletion KNSemiModalViewControllerDemo/KNThirdViewController.m
Expand Up @@ -17,17 +17,21 @@ @interface KNThirdViewController ()
@implementation KNThirdViewController
@synthesize helpLabel;
@synthesize dismissButton;
@synthesize resizeButton;

- (void)viewDidLoad {
[super viewDidLoad];

dismissButton.layer.cornerRadius = 10.0f;
dismissButton.layer.masksToBounds = YES;
resizeButton.layer.cornerRadius = 10.0f;
resizeButton.layer.masksToBounds = YES;
}

- (void)viewDidUnload {
[self setHelpLabel:nil];
[self setDismissButton:nil];
[self setResizeButton:nil];
[super viewDidUnload];
}

Expand All @@ -42,4 +46,11 @@ - (IBAction)dismissButtonDidTouch:(id)sender {

}

- (IBAction)resizeSemiModalView:(id)sender {
UIViewController * parent = [self.view containingViewController];
if ([parent respondsToSelector:@selector(resizeSemiView:)]) {
[parent resizeSemiView:CGSizeMake(320, arc4random() % 280 + 180)];
}
}

@end
101 changes: 78 additions & 23 deletions KNSemiModalViewControllerDemo/KNThirdViewController.xib
Expand Up @@ -2,19 +2,19 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.SystemVersion">11E2620</string>
<string key="IBDocument.InterfaceBuilderVersion">2549</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1181</string>
<string key="NS.object.0">1498</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
<string>IBUIButton</string>
<string>IBUIView</string>
<string>IBUILabel</string>
<string>IBProxyObject</string>
<string>IBUIView</string>
</array>
<array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
Expand Down Expand Up @@ -73,10 +73,10 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<object class="IBUIButton" id="935841964">
<reference key="NSNextResponder" ref="254917508"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{106, 103}, {108, 37}}</string>
<string key="NSFrame">{{35, 98}, {108, 37}}</string>
<reference key="NSSuperview" ref="254917508"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="NSNextKeyView" ref="804381274"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
Expand All @@ -88,28 +88,51 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<int key="IBUIContentVerticalAlignment">0</int>
<string key="IBUITitleShadowOffset">{0, 1}</string>
<string key="IBUINormalTitle">Dismiss</string>
<object class="NSColor" key="IBUIHighlightedTitleColor">
<object class="NSColor" key="IBUIHighlightedTitleColor" id="929823389">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<object class="NSColor" key="IBUINormalTitleColor" id="386475050">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleShadowColor">
<object class="NSColor" key="IBUINormalTitleShadowColor" id="593932880">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<object class="IBUIFontDescription" key="IBUIFontDescription" id="120782918">
<int key="type">2</int>
<double key="pointSize">15</double>
</object>
<object class="NSFont" key="IBUIFont">
<object class="NSFont" key="IBUIFont" id="509391230">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">15</double>
<int key="NSfFlags">16</int>
</object>
</object>
<object class="IBUIButton" id="804381274">
<reference key="NSNextResponder" ref="254917508"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{178, 98}, {108, 37}}</string>
<reference key="NSSuperview" ref="254917508"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAwLjAxMTc4ODY1NjE0IDAAA</bytes>
</object>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<string key="IBUITitleShadowOffset">{0, 1}</string>
<string key="IBUINormalTitle">Resize</string>
<reference key="IBUIHighlightedTitleColor" ref="929823389"/>
<reference key="IBUINormalTitleColor" ref="386475050"/>
<reference key="IBUINormalTitleShadowColor" ref="593932880"/>
<reference key="IBUIFontDescription" ref="120782918"/>
<reference key="IBUIFont" ref="509391230"/>
</object>
</array>
<string key="NSFrameSize">{320, 180}</string>
<reference key="NSSuperview"/>
Expand Down Expand Up @@ -149,6 +172,14 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
</object>
<int key="connectionID">8</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">resizeButton</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="804381274"/>
</object>
<int key="connectionID">13</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">dismissButtonDidTouch:</string>
Expand All @@ -158,6 +189,15 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
</object>
<int key="connectionID">9</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">resizeSemiModalView:</string>
<reference key="source" ref="804381274"/>
<reference key="destination" ref="841351856"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">12</int>
</object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
Expand All @@ -182,8 +222,9 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<int key="objectID">3</int>
<reference key="object" ref="254917508"/>
<array class="NSMutableArray" key="children">
<reference ref="935841964"/>
<reference ref="349859885"/>
<reference ref="935841964"/>
<reference ref="804381274"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -197,13 +238,19 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<reference key="object" ref="935841964"/>
<reference key="parent" ref="254917508"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">10</int>
<reference key="object" ref="804381274"/>
<reference key="parent" ref="254917508"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.CustomClassName">KNThirdViewController</string>
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="3.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
Expand All @@ -212,27 +259,31 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">9</int>
<int key="maxID">13</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">KNThirdViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">dismissButtonDidTouch:</string>
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">dismissButtonDidTouch:</string>
<object class="IBActionInfo" key="NS.object.0">
<dictionary class="NSMutableDictionary" key="actions">
<string key="dismissButtonDidTouch:">id</string>
<string key="resizeSemiModalView:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
<object class="IBActionInfo" key="dismissButtonDidTouch:">
<string key="name">dismissButtonDidTouch:</string>
<string key="candidateClassName">id</string>
</object>
</object>
<object class="IBActionInfo" key="resizeSemiModalView:">
<string key="name">resizeSemiModalView:</string>
<string key="candidateClassName">id</string>
</object>
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="dismissButton">UIButton</string>
<string key="helpLabel">UILabel</string>
<string key="resizeButton">UIButton</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
<object class="IBToOneOutletInfo" key="dismissButton">
Expand All @@ -243,6 +294,10 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
<string key="name">helpLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="resizeButton">
<string key="name">resizeButton</string>
<string key="candidateClassName">UIButton</string>
</object>
</dictionary>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
Expand All @@ -259,6 +314,6 @@ IHlvdSBrbm93IHdoYXQgeW91IGFyZSBkb2luZyk</string>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1181</string>
<string key="IBCocoaTouchPluginVersion">1498</string>
</data>
</archive>
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ Download a demo clip [here](https://github.com/kentnguyen/KNSemiModalViewControl
* Works with UIViewController contained inside UINavigationController, contained inside UITabbarController
* Auto handling of modal frame size
* Auto handling of touch area for dismissal

* Resizable after presenting so that keyboard related interactions are possible
* Easy to understand and very small code base, only 2 files
* Trivial to implement as subclass
* Only use basic CAAnimation, should work fine with SDK 4.x up.
Expand Down
1 change: 1 addition & 0 deletions Source/UIViewController+KNSemiModal.h
Expand Up @@ -13,6 +13,7 @@
-(void)presentSemiViewController:(UIViewController*)vc;
-(void)presentSemiView:(UIView*)vc;
-(void)dismissSemiModalView;
-(void)resizeSemiView:(CGSize)newSize;

@end

Expand Down
12 changes: 12 additions & 0 deletions Source/UIViewController+KNSemiModal.m
Expand Up @@ -141,6 +141,18 @@ -(void)dismissSemiModalView {
}];
}

- (void)resizeSemiView:(CGSize)newSize {
UIView * target = [self parentTarget];
UIView * modal = [target.subviews objectAtIndex:target.subviews.count-1];
CGRect mf = modal.frame;
mf.size.width = newSize.width;
mf.size.height = newSize.height;
mf.origin.y = target.frame.size.height - mf.size.height;
[UIView animateWithDuration:kSemiModalAnimationDuration animations:^{
modal.frame = mf;
}];
}

@end

#pragma mark -
Expand Down

0 comments on commit a724099

Please sign in to comment.