Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

barbutton support #78

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FPPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
/** @brief Presenting the popover from a specified point **/
-(void)presentPopoverFromPoint:(CGPoint)fromPoint;

/** @brief PResenting the popover from uibarbuttonitem **/
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem*)barButtonItem;


/** @brief Dismiss the popover **/
-(void)dismissPopoverAnimated:(BOOL)animated;

Expand Down
23 changes: 22 additions & 1 deletion FPPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


#import "FPPopoverController.h"
#import "UIBarButtonItem+FPPopover.h"

//ivars
@interface FPPopoverController()
Expand Down Expand Up @@ -144,6 +145,8 @@ -(id)initWithViewController:(UIViewController*)viewController
[_touchView addSubview:_contentView];

[_contentView addContentView:_viewController.view];
[self addChildViewController:_viewController];

_viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.clipsToBounds = NO;
Expand Down Expand Up @@ -243,9 +246,10 @@ -(void)presentPopoverFromPoint:(CGPoint)fromPoint
//keep the first subview
if(_window.subviews.count > 0)
{
[_viewController beginAppearanceTransition:YES animated:NO];
_parentView = [_window.subviews objectAtIndex:0];
[_parentView addSubview:self.view];
[_viewController viewDidAppear:YES];
[_viewController endAppearanceTransition];
}

}
Expand Down Expand Up @@ -305,6 +309,12 @@ -(CGPoint)originFromView:(UIView*)fromView
return p;
}

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem*)barButtonItem {
UIView *lastView = [self lastView];
CGRect rect = [barButtonItem frameInView:lastView];
[self presentPopoverFromPoint:CGPointMake(rect.origin.x + rect.size.width/2, rect.size.height + rect.origin.y)];
}

-(void)presentPopoverFromView:(UIView*)fromView
{
SAFE_ARC_RELEASE(_fromView);
Expand Down Expand Up @@ -603,6 +613,17 @@ -(void)setAlpha:(CGFloat)alpha
self.view.alpha = alpha;
}

#pragma mark - View Helpers

- (UIView*)lastView {
UIWindow *w = [[UIApplication sharedApplication] keyWindow];
if (w.subviews.count > 0) {
return [w.subviews objectAtIndex:0];
} else {
return w;
}
}




Expand Down
6 changes: 6 additions & 0 deletions FPPopoverDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
18EF6DEB154ED27D005AB1DD /* background.png in Resources */ = {isa = PBXBuildFile; fileRef = 18EF6DE9154ED27D005AB1DD /* background.png */; };
18EF6DEC154ED27D005AB1DD /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 18EF6DEA154ED27D005AB1DD /* [email protected] */; };
18F357271584E6E700AD4F07 /* FPDemoTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18F357261584E6E700AD4F07 /* FPDemoTableViewController.m */; };
EDF3CDC517C517C7000331D4 /* UIBarButtonItem+FPPopover.m in Sources */ = {isa = PBXBuildFile; fileRef = EDF3CDC417C517C7000331D4 /* UIBarButtonItem+FPPopover.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -105,6 +106,8 @@
18EF6DEA154ED27D005AB1DD /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
18F357251584E6E700AD4F07 /* FPDemoTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FPDemoTableViewController.h; sourceTree = "<group>"; };
18F357261584E6E700AD4F07 /* FPDemoTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FPDemoTableViewController.m; sourceTree = "<group>"; };
EDF3CDC317C517C6000331D4 /* UIBarButtonItem+FPPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIBarButtonItem+FPPopover.h"; sourceTree = "<group>"; };
EDF3CDC417C517C7000331D4 /* UIBarButtonItem+FPPopover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIBarButtonItem+FPPopover.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -237,6 +240,8 @@
186C43931538512A00502D64 /* FPPopover */ = {
isa = PBXGroup;
children = (
EDF3CDC317C517C6000331D4 /* UIBarButtonItem+FPPopover.h */,
EDF3CDC417C517C7000331D4 /* UIBarButtonItem+FPPopover.m */,
18E1272F16D97A6500FB6CD0 /* ARCMacros.h */,
186C43941538513B00502D64 /* FPPopoverController.h */,
186C43951538513B00502D64 /* FPPopoverController.m */,
Expand Down Expand Up @@ -447,6 +452,7 @@
186C43A115386E2200502D64 /* DemoTableController.m in Sources */,
18F357271584E6E700AD4F07 /* FPDemoTableViewController.m in Sources */,
18C427041764920D001D4A24 /* FPPopoverKeyboardResponsiveController.m in Sources */,
EDF3CDC517C517C7000331D4 /* UIBarButtonItem+FPPopover.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 8 additions & 0 deletions FPPopoverDemo/DemoTableController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ - (void)viewDidLoad
self.title = @"Popover Title";
}

- (void)viewWillAppear:(BOOL)animated {

}

- (void)viewDidAppear:(BOOL)animated {

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
Expand Down
11 changes: 10 additions & 1 deletion FPPopoverDemo/FPViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import "FPPopoverController.h"
#import "FPDemoTableViewController.h"
#import "UIBarButtonItem+FPPopover.h"


@interface FPViewController ()
Expand All @@ -24,7 +25,12 @@ @implementation FPViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
UIBarButtonItem *barButtonSample = [[UIBarButtonItem alloc]initWithTitle:@"BarButtonSample"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(popover:)];
self.navigationItem.rightBarButtonItem = barButtonSample;

//KEYBOARD OBSERVERS
/************************/
Expand Down Expand Up @@ -93,6 +99,9 @@ -(IBAction)popover:(id)sender
popover.arrowDirection = FPPopoverNoArrow;
[popover presentPopoverFromPoint: CGPointMake(self.view.center.x, self.view.center.y - popover.contentSize.height/2)];
}
else if ([sender isKindOfClass:[UIBarButtonItem class]]) {
[popover presentPopoverFromBarButtonItem:sender];
}
else {
//sender is the UIButton view
popover.arrowDirection = FPPopoverArrowDirectionAny;
Expand Down
Loading