Skip to content

Commit

Permalink
Merge pull request #17 from gereons/landscape
Browse files Browse the repository at this point in the history
add landscape and rotation support
  • Loading branch information
Oliver Clark Rickard committed Jan 14, 2013
2 parents ce6843c + a3695c6 commit 3739e50
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 328 deletions.
1 change: 1 addition & 0 deletions PopoverView/PopoverView.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#pragma mark - Dismissal
//Dismisses the view, and removes it from the view stack.
- (void)dismiss;
- (void)dismiss:(BOOL)animated;

#pragma mark - Activity Indicator Methods

Expand Down
481 changes: 210 additions & 271 deletions PopoverView/PopoverView.m

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions PopoverView/PopoverView_Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@

//normal text color
#define kTextColor [UIColor colorWithRed:0.329 green:0.341 blue:0.353 alpha:1]
// highlighted text color
#define kTextHighlightColor [UIColor colorWithRed:0.098 green:0.102 blue:0.106 alpha:1.000]

//normal text alignment
#define kTextAlignment UITextAlignmentCenter
Expand Down
6 changes: 4 additions & 2 deletions popover/Demo/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#import <UIKit/UIKit.h>
#import "PopoverView.h"

@interface ViewController : UIViewController <PopoverViewDelegate, UITableViewDataSource, UITableViewDelegate> {
@interface ViewController : UIViewController <PopoverViewDelegate, UITableViewDataSource, UITableViewDelegate>
{
PopoverView *pv;

UILabel *tapAnywhereLabel;
CGPoint point;
}

@end
161 changes: 109 additions & 52 deletions popover/Demo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ @interface ViewController ()

@implementation ViewController



#pragma mark - Setup Methods

- (void)viewDidLoad
Expand All @@ -32,37 +30,60 @@ - (void)viewDidLoad
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[self.view addGestureRecognizer:[tap autorelease]];

//Create a label centered on the screen
UILabel *tapAnywhereLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMidX(self.view.bounds) - 200.f*0.5f, CGRectGetMidY(self.view.bounds) - 30.f*0.5f, 200.f, 30.f)];
// Create a label centered on the screen
tapAnywhereLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
tapAnywhereLabel.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
tapAnywhereLabel.text = @"Tap Anywhere";
tapAnywhereLabel.textAlignment = UITextAlignmentCenter;
[self.view addSubview:[tapAnywhereLabel autorelease]];
}



#pragma mark - User Interaction Methods

#pragma mark EXAMPLE CODE IS HERE

- (void)tapped:(UITapGestureRecognizer *)tap {
CGPoint point = [tap locationInView:self.view];

//Here are a couple of different options for how to display the Popover

// [PopoverView showPopoverAtPoint:point inView:self.view withText:@"This is a very long popover box. As you can see, it goes to multiple lines in size." delegate:self]; //Show text wrapping popover with long string

// [PopoverView showPopoverAtPoint:point inView:self.view withTitle:@"This is a title" withText:@"This is text" delegate:self]; //Show text with title
- (void)tapped:(UITapGestureRecognizer *)tap
{
point = [tap locationInView:self.view];
//NSLog(@"tapped at %@", NSStringFromCGPoint(point));

// [PopoverView showPopoverAtPoint:point inView:self.view withStringArray:kStringArray delegate:self]; //Show the string array defined at top of this file
// Here are a couple of different options for how to display the Popover

[PopoverView showPopoverAtPoint:point inView:self.view withTitle:@"Was this helpful?" withStringArray:kStringArray delegate:self]; //Show string array defined at top of this file with title.
// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withText:@"This is a very long popover box. As you can see, it goes to multiple lines in size." delegate:self]; // Show text wrapping popover with long string

// [PopoverView showPopoverAtPoint:point inView:self.view withStringArray:kStringArray withImageArray:kImageArray delegate:self];
// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withTitle:@"This is a title"
// withText:@"This is text"
// delegate:self]; // Show text with title

// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withStringArray:kStringArray
// delegate:self]; // Show the string array defined at top of this file

// [PopoverView showPopoverAtPoint:point inView:self.view withTitle:@"DEBUG" withStringArray:kStringArray withImageArray:kImageArray delegate:self];
pv = [PopoverView showPopoverAtPoint:point
inView:self.view
withTitle:@"Was this helpful?"
withStringArray:kStringArray
delegate:self]; // Show string array defined at top of this file with title.

// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withStringArray:kStringArray
// withImageArray:kImageArray
// delegate:self];

// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withTitle:@"DEBUG"
// withStringArray:kStringArray
// withImageArray:kImageArray
// delegate:self];

// //Here's a little bit more advanced sample. I create a custom view, and hand it off to the PopoverView to display for me. I round the corners
// // Here's a little bit more advanced sample. I create a custom view, and hand it off to the PopoverView to display for me. I round the corners
// OCDaysView *daysView = [[OCDaysView alloc] initWithFrame:CGRectMake(0, 0, 150, 100)];
// [daysView setMonth:10];
// [daysView setYear:2012];
Expand All @@ -71,75 +92,111 @@ - (void)tapped:(UITapGestureRecognizer *)tap {
// daysView.layer.borderWidth = 0.5f; //One retina pixel width
// daysView.layer.cornerRadius = 4.f;
// daysView.layer.masksToBounds = YES;

// pv = [PopoverView showPopoverAtPoint:point inView:self.view withContentView:[daysView autorelease] delegate:self]; //Show calendar with no title
// [PopoverView showPopoverAtPoint:point inView:self.view withTitle:@"October 2012" withContentView:[daysView autorelease] delegate:self]; //Show calendar with title
//
// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withContentView:[daysView autorelease]
// delegate:self]; // Show calendar with no title
// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withTitle:@"October 2012"
// withContentView:[daysView autorelease]
// delegate:self]; // Show calendar with title

// UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
// tableView.delegate = self;
// tableView.dataSource = self;
// pv = [[PopoverView showPopoverAtPoint:point inView:self.view withContentView:tableView delegate:self] retain];
// pv = [PopoverView showPopoverAtPoint:point
// inView:self.view
// withContentView:tableView
// delegate:self];
[pv retain];
}



#pragma mark - DEMO - UITableView Delegate Methods

//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// return 10;
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// return 25;
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
// cell.textLabel.text = @"text";
// cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:12.f];
//
// return [cell autorelease];
//}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 25;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = @"text";
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:12.f];

return [cell autorelease];
}

#pragma mark - PopoverViewDelegate Methods

- (void)popoverView:(PopoverView *)popoverView didSelectItemAtIndex:(NSInteger)index {
- (void)popoverView:(PopoverView *)popoverView didSelectItemAtIndex:(NSInteger)index
{
NSLog(@"%s item:%d", __PRETTY_FUNCTION__, index);

//Figure out which string was selected, store in "string"
// Figure out which string was selected, store in "string"
NSString *string = [kStringArray objectAtIndex:index];

//Show a success image, with the string from the array
// Show a success image, with the string from the array
[popoverView showImage:[UIImage imageNamed:@"success"] withMessage:string];

//Dismiss the PopoverView after 0.5 seconds
// alternatively, you can use
// [popoverView showSuccess];
// or
// [popoverView showError];

// Dismiss the PopoverView after 0.5 seconds
[popoverView performSelector:@selector(dismiss) withObject:nil afterDelay:0.5f];
}

- (void)popoverViewDidDismiss:(PopoverView *)popoverView {
- (void)popoverViewDidDismiss:(PopoverView *)popoverView
{
NSLog(@"%s", __PRETTY_FUNCTION__);
[pv release], pv = nil;
}



#pragma mark - UIViewController Methods

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
[pv release], pv = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
// or, depending on the app setup, one of
// return UIInterfaceOrientationIsPortrait(interfaceOrientation);
// return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(pv) {
[pv animateRotationToNewPoint:CGPointMake(self.view.frame.size.width*0.5f, self.view.frame.size.height*0.5f) inView:self.view withDuration:duration];
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// get new center coords
CGPoint center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));

// move label's center
tapAnywhereLabel.center = center;

if (pv) {
// popover is visible, so we need to either reposition or dismiss it (dismising is probably best to avoid confusion)
bool dismiss = YES;
if (dismiss) {
[pv dismiss:NO];
}
else {
// move popover
[pv animateRotationToNewPoint:center
inView:self.view
withDuration:duration];
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions popover/Demo/popover-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Expand Down

0 comments on commit 3739e50

Please sign in to comment.