diff --git a/README.md b/README.md index cc283cf4..d04606ff 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,12 @@ WYPopoverController is for the presentation of content in popover on iPhone / iP * UIAppearance support * Works like UIPopoverController +* Animation options * Automatic orientation support * UIStoryboard support * Keyboard show / hide support * iOS 6 & 7 support - ### UIAppearance support --- @@ -94,6 +94,27 @@ Determines whether the default content appearance should be used for the popover The margins that define the portion of the screen in which it is permissible to display the popover. +### Animation options + +--- + +Introduced in release 0.1.7, there are 3 styles of animation : +* Fade *(by default)* +* Scale +* Fade with Scale + +#### Examples + +```objective-c + +popover = [[WYPopoverController alloc] initWithContentViewController:contentViewController]; +[popover presentPopoverFromRect:btn.bounds + inView:btn + permittedArrowDirections:WYPopoverArrowDirectionAny + animated:YES + options:WYPopoverAnimationOptionFadeWithScale]; +``` + ### ARC --- @@ -108,13 +129,13 @@ WYPopoverController uses ARC. #### Cocoapods -Add this line `pod 'WYPopoverController', '~> 0.1.5'` to your PodFile. +Add this line `pod 'WYPopoverController', '~> 0.1.7'` to your PodFile. Your PodFile should look like : ```Ruby platform :ios, '6.0' -pod 'WYPopoverController', '~> 0.1.5' +pod 'WYPopoverController', '~> 0.1.7' ``` To use the `master` branch of the repo : diff --git a/WYPopoverController/WYPopoverController.h b/WYPopoverController/WYPopoverController.h index 24e36dc5..a992ffad 100644 --- a/WYPopoverController/WYPopoverController.h +++ b/WYPopoverController/WYPopoverController.h @@ -1,5 +1,5 @@ /* - Version 0.1.6 + Version 0.1.7 WYPopoverController is available under the MIT license. @@ -30,7 +30,7 @@ @protocol WYPopoverControllerDelegate; #ifndef WY_POPOVER_DEFAULT_ANIMATION_DURATION - #define WY_POPOVER_DEFAULT_ANIMATION_DURATION 0.20f + #define WY_POPOVER_DEFAULT_ANIMATION_DURATION .20f #endif typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) { @@ -43,6 +43,12 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) { WYPopoverArrowDirectionUnknown = NSUIntegerMax }; +typedef NS_OPTIONS(NSUInteger, WYPopoverAnimationOptions) { + WYPopoverAnimationOptionFade = 1UL << 0, // default + WYPopoverAnimationOptionScale = 1UL << 1, + WYPopoverAnimationOptionFadeWithScale = WYPopoverAnimationOptionFade | WYPopoverAnimationOptionScale +}; + //////////////////////////////////////////////////////////////////////////////////////////////////////// @interface WYPopoverBackgroundView : UIView @@ -106,6 +112,20 @@ typedef NS_OPTIONS(NSUInteger, WYPopoverArrowDirection) { - (void)presentPopoverAsDialogAnimated:(BOOL)animated; +- (void)presentPopoverFromRect:(CGRect)rect + inView:(UIView *)view + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)animated + options:(WYPopoverAnimationOptions)options; + +- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)animated + options:(WYPopoverAnimationOptions)options; + +- (void)presentPopoverAsDialogAnimated:(BOOL)animated + options:(WYPopoverAnimationOptions)options; + - (void)dismissPopoverAnimated:(BOOL)animated; @end diff --git a/WYPopoverController/WYPopoverController.m b/WYPopoverController/WYPopoverController.m index 97187f17..d2930413 100644 --- a/WYPopoverController/WYPopoverController.m +++ b/WYPopoverController/WYPopoverController.m @@ -1,5 +1,5 @@ /* - Version 0.1.6 + Version 0.1.7 WYPopoverController is available under the MIT license. @@ -1339,6 +1339,8 @@ @interface WYPopoverController () __weak UIBarButtonItem *barButtonItem; CGRect keyboardRect; BOOL hasAppearanceProxyAvailable; + + WYPopoverAnimationOptions options; } @property (nonatomic, strong, readonly) UIView *rootView; @@ -1403,12 +1405,14 @@ - (UIView *)rootView if (result.subviews.count > 0) { - for (UIView *view in result.subviews) { - if(!view.isHidden){ - return view; - } - } -// result = [result.subviews lastObject]; + for (UIView *view in result.subviews) + { + if(!view.isHidden) + { + return view; + } + } + // result = [result.subviews lastObject]; } return result; @@ -1492,7 +1496,39 @@ - (CGSize)contentSizeForViewInPopover return result; } -- (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections animated:(BOOL)aAnimated +- (void)presentPopoverFromRect:(CGRect)aRect + inView:(UIView *)aView + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)aAnimated +{ + [self presentPopoverFromRect:aRect + inView:aView + permittedArrowDirections:arrowDirections + animated:aAnimated + options:WYPopoverAnimationOptionFade]; +} + +- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)aAnimated +{ + [self presentPopoverFromBarButtonItem:item + permittedArrowDirections:arrowDirections + animated:aAnimated + options:WYPopoverAnimationOptionFade]; +} + +- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated +{ + [self presentPopoverAsDialogAnimated:aAnimated + options:WYPopoverAnimationOptionFade]; +} + +- (void)presentPopoverFromRect:(CGRect)aRect + inView:(UIView *)aView + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)aAnimated + options:(WYPopoverAnimationOptions)aOptions { NSAssert((arrowDirections != WYPopoverArrowDirectionUnknown), @"WYPopoverArrowDirection must not be UNKNOWN"); @@ -1500,6 +1536,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr inView = aView; permittedArrowDirections = arrowDirections; animated = aAnimated; + options = aOptions; CGSize contentViewSize = self.contentSizeForViewInPopover; @@ -1567,11 +1604,23 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr if (animated) { - containerView.alpha = 0; + if ((options & WYPopoverAnimationOptionFade) == WYPopoverAnimationOptionFade) + { + containerView.alpha = 0; + } + [viewController viewWillAppear:YES]; + if ((options & WYPopoverAnimationOptionScale) == WYPopoverAnimationOptionScale) + { + CGAffineTransform transform = [self transformTranslateForArrowDirection:containerView.arrowDirection]; + transform = CGAffineTransformScale(transform, 0, 0); + containerView.transform = transform; + } + [UIView animateWithDuration:WY_POPOVER_DEFAULT_ANIMATION_DURATION animations:^{ containerView.alpha = 1; + containerView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { if ([viewController isKindOfClass:[UINavigationController class]] == NO) { @@ -1614,6 +1663,63 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr } } +- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)aAnimated + options:(WYPopoverAnimationOptions)aOptions +{ + barButtonItem = item; + UIView *itemView = [barButtonItem valueForKey:@"view"]; + arrowDirections = WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp; + [self presentPopoverFromRect:itemView.bounds + inView:itemView + permittedArrowDirections:arrowDirections + animated:aAnimated + options:aOptions]; +} + +- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated + options:(WYPopoverAnimationOptions)aOptions +{ + [self presentPopoverFromRect:CGRectZero + inView:nil + permittedArrowDirections:WYPopoverArrowDirectionNone + animated:aAnimated + options:aOptions]; +} + +- (CGAffineTransform)transformTranslateForArrowDirection:(WYPopoverArrowDirection)arrowDirection +{ + CGAffineTransform transform = CGAffineTransformIdentity; + + if (containerView.arrowHeight > 0) + { + CGSize containerViewSize = containerView.frame.size; + + if (arrowDirection == WYPopoverArrowDirectionDown) + { + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.arrowOffset, containerViewSize.height / 2); + } + + if (arrowDirection == WYPopoverArrowDirectionUp) + { + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.arrowOffset, -containerViewSize.height / 2); + } + + if (arrowDirection == WYPopoverArrowDirectionRight) + { + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.frame.size.width / 2, containerView.arrowOffset); + } + + if (arrowDirection == WYPopoverArrowDirectionLeft) + { + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -containerView.frame.size.width / 2, containerView.arrowOffset); + } + } + + return transform; +} + - (void)setPopoverNavigationBarBackgroundImage { if (wantsDefaultContentAppearance == NO && [viewController isKindOfClass:[UINavigationController class]]) @@ -1644,19 +1750,6 @@ - (void)setPopoverNavigationBarBackgroundImage } } -- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections animated:(BOOL)aAnimated -{ - barButtonItem = item; - UIView *itemView = [barButtonItem valueForKey:@"view"]; - arrowDirections = WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp; - [self presentPopoverFromRect:itemView.bounds inView:itemView permittedArrowDirections:arrowDirections animated:aAnimated]; -} - -- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated -{ - [self presentPopoverFromRect:CGRectZero inView:nil permittedArrowDirections:WYPopoverArrowDirectionNone animated:aAnimated]; -} - - (void)positionPopover { CGSize contentViewSize = self.contentSizeForViewInPopover; diff --git a/WYPopoverController/WYStoryboardPopoverSegue.h b/WYPopoverController/WYStoryboardPopoverSegue.h index 994125ee..c37c027b 100644 --- a/WYPopoverController/WYStoryboardPopoverSegue.h +++ b/WYPopoverController/WYStoryboardPopoverSegue.h @@ -1,5 +1,5 @@ /* - Version 0.1.6 + Version 0.1.7 WYPopoverController is available under the MIT license. @@ -28,6 +28,13 @@ @interface WYStoryboardPopoverSegue : UIStoryboardSegue -- (WYPopoverController*)popoverControllerWithSender:(id)sender permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections animated:(BOOL)animated; +- (WYPopoverController*)popoverControllerWithSender:(id)sender + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)animated; + +- (WYPopoverController*)popoverControllerWithSender:(id)sender + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections + animated:(BOOL)animated + options:(WYPopoverAnimationOptions)options; @end \ No newline at end of file diff --git a/WYPopoverController/WYStoryboardPopoverSegue.m b/WYPopoverController/WYStoryboardPopoverSegue.m index 2685c517..bfa1fc7b 100644 --- a/WYPopoverController/WYStoryboardPopoverSegue.m +++ b/WYPopoverController/WYStoryboardPopoverSegue.m @@ -1,5 +1,5 @@ /* - Version 0.1.6 + Version 0.1.7 WYPopoverController is available under the MIT license. @@ -30,9 +30,10 @@ of this software and associated documentation files (the "Software"), to deal @interface WYStoryboardPopoverSegue() { - WYPopoverController* popoverController; + WYPopoverController *popoverController; id sender; WYPopoverArrowDirection arrowDirections; + WYPopoverAnimationOptions options; BOOL animated; } @@ -46,20 +47,41 @@ - (void)perform { if ([sender isKindOfClass:[UIBarButtonItem class]]) { - [popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem*)sender permittedArrowDirections:arrowDirections animated:animated]; + [popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem*)sender + permittedArrowDirections:arrowDirections + animated:animated + options:options]; } else if ([sender isKindOfClass:[UIView class]]) { - UIView* view = (UIView*)sender; - [popoverController presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:arrowDirections animated:animated]; + UIView *view = (UIView *)sender; + [popoverController presentPopoverFromRect:view.bounds + inView:view + permittedArrowDirections:arrowDirections + animated:animated + options:options]; } } -- (WYPopoverController*)popoverControllerWithSender:(id)aSender permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections animated:(BOOL)aAnimated +- (WYPopoverController *)popoverControllerWithSender:(id)aSender + permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections + animated:(BOOL)aAnimated +{ + return [self popoverControllerWithSender:aSender + permittedArrowDirections:aArrowDirections + animated:aAnimated + options:WYPopoverAnimationOptionFade]; +} + +- (WYPopoverController *)popoverControllerWithSender:(id)aSender + permittedArrowDirections:(WYPopoverArrowDirection)aArrowDirections + animated:(BOOL)aAnimated + options:(WYPopoverAnimationOptions)aOptions { sender = aSender; arrowDirections = aArrowDirections; animated = aAnimated; + options = aOptions; popoverController = [[WYPopoverController alloc] initWithContentViewController:self.destinationViewController]; diff --git a/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m b/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m index c98caa97..a3e9fbb3 100644 --- a/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m +++ b/demos/Demo/WYPopoverDemo/WYAllDirectionsViewController.m @@ -83,7 +83,12 @@ - (IBAction)showPopover:(id)sender settingsPopoverController.passthroughViews = @[btn]; settingsPopoverController.popoverLayoutMargins = UIEdgeInsetsMake(10, 10, 10, 10); settingsPopoverController.wantsDefaultContentAppearance = NO; - [settingsPopoverController presentPopoverFromRect:btn.bounds inView:btn permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES]; + + [settingsPopoverController presentPopoverFromRect:btn.bounds + inView:btn + permittedArrowDirections:WYPopoverArrowDirectionAny + animated:YES + options:WYPopoverAnimationOptionFadeWithScale]; } else { @@ -172,3 +177,28 @@ - (void)didReceiveMemoryWarning } @end + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/Demo/WYPopoverDemo/WYAppDelegate.m b/demos/Demo/WYPopoverDemo/WYAppDelegate.m index 1d119c00..bb2a7969 100644 --- a/demos/Demo/WYPopoverDemo/WYAppDelegate.m +++ b/demos/Demo/WYPopoverDemo/WYAppDelegate.m @@ -20,7 +20,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( //Appearance 1 (white popover) // - WYPopoverBackgroundView* popoverAppearance = [WYPopoverBackgroundView appearance]; + WYPopoverBackgroundView *popoverAppearance = [WYPopoverBackgroundView appearance]; + [popoverAppearance setFillTopColor:[UIColor blackColor]]; + + /* [popoverAppearance setTintColor:[UIColor colorWithRed:235./255. green:235./255. blue:235./255. alpha:1]]; [popoverAppearance setOuterStrokeColor:[UIColor darkGrayColor]]; [popoverAppearance setInnerStrokeColor:[UIColor darkGrayColor]]; @@ -44,11 +47,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [popoverAppearance setInnerShadowOffset:CGSizeMake(0, 1)]; [popoverAppearance setViewContentInsets:UIEdgeInsetsMake(3, 0, 0, 0)]; - - UINavigationBar* navBarAppearance = [UINavigationBar appearanceWhenContainedIn:[WYPopoverBackgroundView class], [UINavigationController class], nil]; + */ + UINavigationBar *navBarAppearance = [UINavigationBar appearanceWhenContainedIn:[WYPopoverBackgroundView class], [UINavigationController class], nil]; [navBarAppearance setTitleTextAttributes:@{ - UITextAttributeTextColor : [UIColor darkGrayColor], - UITextAttributeTextShadowColor: [UIColor whiteColor], + UITextAttributeTextColor : [UIColor whiteColor], + UITextAttributeTextShadowColor: [UIColor clearColor], UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)] }];