Skip to content

Commit

Permalink
added example in demo that handles keyboard showing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvise Susmel committed Jun 9, 2013
1 parent 2a7927d commit 8131c50
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 12 deletions.
8 changes: 6 additions & 2 deletions FPPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


@class FPPopoverController;

@protocol FPPopoverControllerDelegate <NSObject>

@optional
Expand All @@ -25,7 +26,9 @@
@end

@interface FPPopoverController : UIViewController

{
UIView *_parentView;
}
//ARC-enable and disable support
#if __has_feature(objc_arc)
@property(nonatomic,assign) id<FPPopoverControllerDelegate> delegate;
Expand Down Expand Up @@ -74,7 +77,8 @@ typedef void (^FPPopoverCompletion)();
/** @brief Hide the shadows to get better performances **/
-(void)setShadowsHidden:(BOOL)hidden;


/** @brief Refresh popover **/
-(void)setupView;


@end
5 changes: 4 additions & 1 deletion FPPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ @interface FPPopoverController()
FPPopoverView *_contentView;
UIViewController *_viewController;
UIWindow *_window;
UIView *_parentView;
UIView *_fromView;
UIDeviceOrientation _deviceOrientation;

Expand Down Expand Up @@ -64,6 +63,7 @@ -(void)addObservers
selector:@selector(deviceOrientationDidChange:)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willPresentNewPopover:) name:@"FPNewPopoverPresented" object:nil];
Expand Down Expand Up @@ -603,4 +603,7 @@ -(void)setAlpha:(CGFloat)alpha
self.view.alpha = alpha;
}




@end
6 changes: 6 additions & 0 deletions FPPopoverDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
186C438D1538512200502D64 /* FPViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 186C438B1538512200502D64 /* FPViewController_iPad.xib */; };
186C439B153851F600502D64 /* Readme.md in Resources */ = {isa = PBXBuildFile; fileRef = 186C439A153851F600502D64 /* Readme.md */; };
186C43A115386E2200502D64 /* DemoTableController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186C43A015386E2200502D64 /* DemoTableController.m */; };
18C427041764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18C427031764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m */; };
18D8FA31155050F0005E2222 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 186C43751538512100502D64 /* Foundation.framework */; };
18D8FA3B155050FE005E2222 /* FPPopoverController.m in Sources */ = {isa = PBXBuildFile; fileRef = 186C43951538513B00502D64 /* FPPopoverController.m */; };
18D8FA3C155050FE005E2222 /* FPPopoverView.m in Sources */ = {isa = PBXBuildFile; fileRef = 186C43971538513B00502D64 /* FPPopoverView.m */; };
Expand Down Expand Up @@ -88,6 +89,8 @@
186C43A015386E2200502D64 /* DemoTableController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoTableController.m; sourceTree = "<group>"; };
186C43AA153CAD1000502D64 /* FPTouchView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPTouchView.h; sourceTree = "<group>"; };
186C43AB153CAD1000502D64 /* FPTouchView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPTouchView.m; sourceTree = "<group>"; };
18C427021764920D001D4A24 /* FPPopoverKeyboardResponsiveController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPPopoverKeyboardResponsiveController.h; sourceTree = "<group>"; };
18C427031764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPPopoverKeyboardResponsiveController.m; sourceTree = "<group>"; };
18D8FA30155050F0005E2222 /* libfppopover.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libfppopover.a; sourceTree = BUILT_PRODUCTS_DIR; };
18D8FA34155050F0005E2222 /* fppopover-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "fppopover-Prefix.pch"; sourceTree = "<group>"; };
18D8FA44155051BA005E2222 /* background_iPad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = background_iPad.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -208,6 +211,8 @@
186C43861538512200502D64 /* FPViewController.m */,
18F357251584E6E700AD4F07 /* FPDemoTableViewController.h */,
18F357261584E6E700AD4F07 /* FPDemoTableViewController.m */,
18C427021764920D001D4A24 /* FPPopoverKeyboardResponsiveController.h */,
18C427031764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m */,
186C43881538512200502D64 /* FPViewController_iPhone.xib */,
186C438B1538512200502D64 /* FPViewController_iPad.xib */,
186C437A1538512100502D64 /* Supporting Files */,
Expand Down Expand Up @@ -441,6 +446,7 @@
186C43871538512200502D64 /* FPViewController.m in Sources */,
186C43A115386E2200502D64 /* DemoTableController.m in Sources */,
18F357271584E6E700AD4F07 /* FPDemoTableViewController.m in Sources */,
18C427041764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions FPPopoverDemo/FPDemoTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "FPDemoTableViewController.h"
#import "FPPopoverController.h"
#import "DemoTableController.h"

@interface FPDemoTableViewController ()

@end
Expand Down
13 changes: 13 additions & 0 deletions FPPopoverDemo/FPPopoverKeyboardResponsiveController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// FPPopoverKeyboardResponsiveController.h
// FPPopoverDemo
//
// Created by Alvise Susmel on 09/06/2013.
// Copyright (c) 2013 Fifty Pixels Ltd. All rights reserved.
//

#import "FPPopoverController.h"

@interface FPPopoverKeyboardResponsiveController : FPPopoverController
@property (assign, nonatomic) CGFloat keyboardHeight;
@end
25 changes: 25 additions & 0 deletions FPPopoverDemo/FPPopoverKeyboardResponsiveController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// FPPopoverKeyboardResponsiveController.m
// FPPopoverDemo
//
// Created by Alvise Susmel on 09/06/2013.
// Copyright (c) 2013 Fifty Pixels Ltd. All rights reserved.
//

#import "FPPopoverKeyboardResponsiveController.h"



@implementation FPPopoverKeyboardResponsiveController




-(CGFloat)parentHeight
{
return _parentView.bounds.size.height - self.keyboardHeight;
}



@end
6 changes: 5 additions & 1 deletion FPPopoverDemo/FPViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#import <UIKit/UIKit.h>
#import "FPPopoverController.h"
#import "ARCMacros.h"

#import "FPPopoverKeyboardResponsiveController.h"

@interface FPViewController : UIViewController <FPPopoverControllerDelegate>
{
FPPopoverController *popover;
FPPopoverKeyboardResponsiveController *popover;
CGFloat _keyboardHeight;
}
//ARC-enable and disable support
#if __has_feature(objc_arc)
Expand Down
36 changes: 33 additions & 3 deletions FPPopoverDemo/FPViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#import "FPPopoverController.h"
#import "FPDemoTableViewController.h"


@interface FPViewController ()

@end
Expand All @@ -24,7 +26,18 @@ - (void)viewDidLoad
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];

//KEYBOARD OBSERVERS
/************************/
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
/************************/
}

- (void)viewDidUnload
Expand Down Expand Up @@ -59,9 +72,9 @@ -(IBAction)popover:(id)sender
//the controller we want to present as a popover
DemoTableController *controller = [[DemoTableController alloc] initWithStyle:UITableViewStylePlain];
controller.delegate = self;
popover = [[FPPopoverController alloc] initWithViewController:controller];
popover = [[FPPopoverKeyboardResponsiveController alloc] initWithViewController:controller];
popover.tint = FPPopoverDefaultTint;

popover.keyboardHeight = _keyboardHeight;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
Expand Down Expand Up @@ -163,7 +176,7 @@ -(IBAction)navControllerPopover:(id)sender
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:controller];
SAFE_ARC_RELEASE(controller); controller=nil;

popover = [[FPPopoverController alloc] initWithViewController:nc];
popover = [[FPPopoverKeyboardResponsiveController alloc] initWithViewController:nc];
popover.tint = FPPopoverDefaultTint;
popover.contentSize = CGSizeMake(300, 500);
[popover presentPopoverFromView:sender];
Expand All @@ -187,4 +200,21 @@ -(void)selectedTableRow:(NSUInteger)rowNum
}


-(void)keyboardWillShow:(NSNotification*)notification {
NSDictionary *info = notification.userInfo;
CGRect keyboardRect = [[info valueForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
_keyboardHeight = keyboardRect.size.height;

//if the popover is present will be refreshed
popover.keyboardHeight = _keyboardHeight;
[popover setupView];
}

-(void)keyboardWillHide:(NSNotification*)notification {
_keyboardHeight = 0.0;

//if the popover is present will be refreshed
popover.keyboardHeight = _keyboardHeight;
[popover setupView];
}
@end
62 changes: 57 additions & 5 deletions FPPopoverDemo/en.lproj/FPViewController_iPhone.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1552</int>
<string key="IBDocument.SystemVersion">12C3012</string>
<string key="IBDocument.SystemVersion">12D78</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<string key="IBDocument.AppKitVersion">1187.37</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">2083</string>
Expand All @@ -14,6 +14,7 @@
<string>IBProxyObject</string>
<string>IBUIButton</string>
<string>IBUIImageView</string>
<string>IBUITextField</string>
<string>IBUIView</string>
</array>
<array key="IBDocument.PluginDependencies">
Expand Down Expand Up @@ -116,7 +117,7 @@
<string key="NSFrame">{{225, 20}, {75, 31}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="252517209"/>
<reference key="NSNextKeyView" ref="221176177"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -254,6 +255,7 @@
<string key="NSFrame">{{217, 409}, {92, 31}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -392,6 +394,44 @@
<reference key="IBUIFontDescription" ref="274917050"/>
<reference key="IBUIFont" ref="26567513"/>
</object>
<object class="IBUITextField" id="221176177">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">288</int>
<string key="NSFrame">{{50, 66}, {221, 30}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="252517209"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentVerticalAlignment">0</int>
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
<string key="IBUIPlaceholder">Try popover with keyboard</string>
<object class="NSColor" key="IBUITextColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace">
<int key="NSID">2</int>
</object>
</object>
<int key="IBUITextAlignment">1</int>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">17</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">1</int>
<double key="pointSize">14</double>
</object>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica</string>
<double key="NSSize">14</double>
<int key="NSfFlags">16</int>
</object>
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
Expand Down Expand Up @@ -597,6 +637,7 @@
<reference ref="598106626"/>
<reference ref="569910789"/>
<reference ref="624459852"/>
<reference ref="221176177"/>
</array>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -675,6 +716,11 @@
<reference key="object" ref="624459852"/>
<reference key="parent" ref="774585933"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">48</int>
<reference key="object" ref="221176177"/>
<reference key="parent" ref="774585933"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -697,13 +743,14 @@
<string key="38.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="40.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="43.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="48.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">47</int>
<int key="maxID">48</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -719,6 +766,7 @@
<string key="midCenter:">id</string>
<string key="midLeft:">id</string>
<string key="midRight:">id</string>
<string key="navControllerPopover:">id</string>
<string key="noArrow:">id</string>
<string key="popover:">id</string>
<string key="rt:">id</string>
Expand Down Expand Up @@ -759,6 +807,10 @@
<string key="name">midRight:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="navControllerPopover:">
<string key="name">navControllerPopover:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="noArrow:">
<string key="name">noArrow:</string>
<string key="candidateClassName">id</string>
Expand Down

0 comments on commit 8131c50

Please sign in to comment.