diff --git a/FPPopoverController.h b/FPPopoverController.h index 9eda7c1..f1a7b73 100644 --- a/FPPopoverController.h +++ b/FPPopoverController.h @@ -16,6 +16,7 @@ @class FPPopoverController; + @protocol FPPopoverControllerDelegate @optional @@ -25,7 +26,9 @@ @end @interface FPPopoverController : UIViewController - +{ + UIView *_parentView; +} //ARC-enable and disable support #if __has_feature(objc_arc) @property(nonatomic,assign) id delegate; @@ -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 diff --git a/FPPopoverController.m b/FPPopoverController.m index 8a1fc9b..28406d4 100644 --- a/FPPopoverController.m +++ b/FPPopoverController.m @@ -16,7 +16,6 @@ @interface FPPopoverController() FPPopoverView *_contentView; UIViewController *_viewController; UIWindow *_window; - UIView *_parentView; UIView *_fromView; UIDeviceOrientation _deviceOrientation; @@ -64,6 +63,7 @@ -(void)addObservers selector:@selector(deviceOrientationDidChange:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPresentNewPopover:) name:@"FPNewPopoverPresented" object:nil]; @@ -603,4 +603,7 @@ -(void)setAlpha:(CGFloat)alpha self.view.alpha = alpha; } + + + @end diff --git a/FPPopoverDemo.xcodeproj/project.pbxproj b/FPPopoverDemo.xcodeproj/project.pbxproj index 2ff8fea..2f2b7e0 100644 --- a/FPPopoverDemo.xcodeproj/project.pbxproj +++ b/FPPopoverDemo.xcodeproj/project.pbxproj @@ -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 */; }; @@ -88,6 +89,8 @@ 186C43A015386E2200502D64 /* DemoTableController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoTableController.m; sourceTree = ""; }; 186C43AA153CAD1000502D64 /* FPTouchView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPTouchView.h; sourceTree = ""; }; 186C43AB153CAD1000502D64 /* FPTouchView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPTouchView.m; sourceTree = ""; }; + 18C427021764920D001D4A24 /* FPPopoverKeyboardResponsiveController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPPopoverKeyboardResponsiveController.h; sourceTree = ""; }; + 18C427031764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPPopoverKeyboardResponsiveController.m; sourceTree = ""; }; 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 = ""; }; 18D8FA44155051BA005E2222 /* background_iPad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = background_iPad.png; sourceTree = ""; }; @@ -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 */, @@ -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; }; diff --git a/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate b/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate index eee646c..e273ef4 100644 Binary files a/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate and b/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/FPPopoverDemo/FPDemoTableViewController.m b/FPPopoverDemo/FPDemoTableViewController.m index 28f9929..af599a7 100644 --- a/FPPopoverDemo/FPDemoTableViewController.m +++ b/FPPopoverDemo/FPDemoTableViewController.m @@ -9,6 +9,7 @@ #import "FPDemoTableViewController.h" #import "FPPopoverController.h" #import "DemoTableController.h" + @interface FPDemoTableViewController () @end diff --git a/FPPopoverDemo/FPPopoverKeyboardResponsiveController.h b/FPPopoverDemo/FPPopoverKeyboardResponsiveController.h new file mode 100644 index 0000000..bb11931 --- /dev/null +++ b/FPPopoverDemo/FPPopoverKeyboardResponsiveController.h @@ -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 diff --git a/FPPopoverDemo/FPPopoverKeyboardResponsiveController.m b/FPPopoverDemo/FPPopoverKeyboardResponsiveController.m new file mode 100644 index 0000000..f5016e1 --- /dev/null +++ b/FPPopoverDemo/FPPopoverKeyboardResponsiveController.m @@ -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 \ No newline at end of file diff --git a/FPPopoverDemo/FPViewController.h b/FPPopoverDemo/FPViewController.h index e655209..9ba3bdf 100644 --- a/FPPopoverDemo/FPViewController.h +++ b/FPPopoverDemo/FPViewController.h @@ -9,9 +9,13 @@ #import #import "FPPopoverController.h" #import "ARCMacros.h" + +#import "FPPopoverKeyboardResponsiveController.h" + @interface FPViewController : UIViewController { - FPPopoverController *popover; + FPPopoverKeyboardResponsiveController *popover; + CGFloat _keyboardHeight; } //ARC-enable and disable support #if __has_feature(objc_arc) diff --git a/FPPopoverDemo/FPViewController.m b/FPPopoverDemo/FPViewController.m index 00c0c5a..8bbad1a 100644 --- a/FPPopoverDemo/FPViewController.m +++ b/FPPopoverDemo/FPViewController.m @@ -11,6 +11,8 @@ #import "FPPopoverController.h" #import "FPDemoTableViewController.h" + + @interface FPViewController () @end @@ -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 @@ -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) { @@ -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]; @@ -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 diff --git a/FPPopoverDemo/en.lproj/FPViewController_iPhone.xib b/FPPopoverDemo/en.lproj/FPViewController_iPhone.xib index c08214a..d6198de 100644 --- a/FPPopoverDemo/en.lproj/FPViewController_iPhone.xib +++ b/FPPopoverDemo/en.lproj/FPViewController_iPhone.xib @@ -2,10 +2,10 @@ 1552 - 12C3012 + 12D78 3084 - 1187.34 - 625.00 + 1187.37 + 626.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin 2083 @@ -14,6 +14,7 @@ IBProxyObject IBUIButton IBUIImageView + IBUITextField IBUIView @@ -116,7 +117,7 @@ {{225, 20}, {75, 31}} - + _NS:9 NO IBCocoaTouchFramework @@ -254,6 +255,7 @@ {{217, 409}, {92, 31}} + _NS:9 NO IBCocoaTouchFramework @@ -392,6 +394,44 @@ + + + 288 + {{50, 66}, {221, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + Try popover with keyboard + + 3 + MAA + + 2 + + + 1 + YES + 17 + + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + + {{0, 20}, {320, 460}} @@ -597,6 +637,7 @@ + @@ -675,6 +716,11 @@ + + 48 + + + @@ -697,13 +743,14 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 47 + 48 @@ -719,6 +766,7 @@ id id id + id id id id @@ -759,6 +807,10 @@ midRight: id + + navControllerPopover: + id + noArrow: id