|
1 | 1 | /* |
2 | | - Version 0.1.6 |
| 2 | + Version 0.1.7 |
3 | 3 | |
4 | 4 | WYPopoverController is available under the MIT license. |
5 | 5 | |
@@ -1339,6 +1339,8 @@ @interface WYPopoverController () <WYPopoverOverlayViewDelegate> |
1339 | 1339 | __weak UIBarButtonItem *barButtonItem; |
1340 | 1340 | CGRect keyboardRect; |
1341 | 1341 | BOOL hasAppearanceProxyAvailable; |
| 1342 | + |
| 1343 | + WYPopoverAnimationOptions options; |
1342 | 1344 | } |
1343 | 1345 |
|
1344 | 1346 | @property (nonatomic, strong, readonly) UIView *rootView; |
@@ -1403,12 +1405,14 @@ - (UIView *)rootView |
1403 | 1405 |
|
1404 | 1406 | if (result.subviews.count > 0) |
1405 | 1407 | { |
1406 | | - for (UIView *view in result.subviews) { |
1407 | | - if(!view.isHidden){ |
1408 | | - return view; |
1409 | | - } |
1410 | | - } |
1411 | | -// result = [result.subviews lastObject]; |
| 1408 | + for (UIView *view in result.subviews) |
| 1409 | + { |
| 1410 | + if(!view.isHidden) |
| 1411 | + { |
| 1412 | + return view; |
| 1413 | + } |
| 1414 | + } |
| 1415 | + // result = [result.subviews lastObject]; |
1412 | 1416 | } |
1413 | 1417 |
|
1414 | 1418 | return result; |
@@ -1492,14 +1496,47 @@ - (CGSize)contentSizeForViewInPopover |
1492 | 1496 | return result; |
1493 | 1497 | } |
1494 | 1498 |
|
1495 | | -- (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections animated:(BOOL)aAnimated |
| 1499 | +- (void)presentPopoverFromRect:(CGRect)aRect |
| 1500 | + inView:(UIView *)aView |
| 1501 | + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections |
| 1502 | + animated:(BOOL)aAnimated |
| 1503 | +{ |
| 1504 | + [self presentPopoverFromRect:aRect |
| 1505 | + inView:aView |
| 1506 | + permittedArrowDirections:arrowDirections |
| 1507 | + animated:aAnimated |
| 1508 | + options:WYPopoverAnimationOptionFade]; |
| 1509 | +} |
| 1510 | + |
| 1511 | +- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item |
| 1512 | + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections |
| 1513 | + animated:(BOOL)aAnimated |
| 1514 | +{ |
| 1515 | + [self presentPopoverFromBarButtonItem:item |
| 1516 | + permittedArrowDirections:arrowDirections |
| 1517 | + animated:aAnimated |
| 1518 | + options:WYPopoverAnimationOptionFade]; |
| 1519 | +} |
| 1520 | + |
| 1521 | +- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated |
| 1522 | +{ |
| 1523 | + [self presentPopoverAsDialogAnimated:aAnimated |
| 1524 | + options:WYPopoverAnimationOptionFade]; |
| 1525 | +} |
| 1526 | + |
| 1527 | +- (void)presentPopoverFromRect:(CGRect)aRect |
| 1528 | + inView:(UIView *)aView |
| 1529 | + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections |
| 1530 | + animated:(BOOL)aAnimated |
| 1531 | + options:(WYPopoverAnimationOptions)aOptions |
1496 | 1532 | { |
1497 | 1533 | NSAssert((arrowDirections != WYPopoverArrowDirectionUnknown), @"WYPopoverArrowDirection must not be UNKNOWN"); |
1498 | 1534 |
|
1499 | 1535 | rect = aRect; |
1500 | 1536 | inView = aView; |
1501 | 1537 | permittedArrowDirections = arrowDirections; |
1502 | 1538 | animated = aAnimated; |
| 1539 | + options = aOptions; |
1503 | 1540 |
|
1504 | 1541 | CGSize contentViewSize = self.contentSizeForViewInPopover; |
1505 | 1542 |
|
@@ -1567,11 +1604,23 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr |
1567 | 1604 |
|
1568 | 1605 | if (animated) |
1569 | 1606 | { |
1570 | | - containerView.alpha = 0; |
| 1607 | + if ((options & WYPopoverAnimationOptionFade) == WYPopoverAnimationOptionFade) |
| 1608 | + { |
| 1609 | + containerView.alpha = 0; |
| 1610 | + } |
| 1611 | + |
1571 | 1612 | [viewController viewWillAppear:YES]; |
1572 | 1613 |
|
| 1614 | + if ((options & WYPopoverAnimationOptionScale) == WYPopoverAnimationOptionScale) |
| 1615 | + { |
| 1616 | + CGAffineTransform transform = [self transformTranslateForArrowDirection:containerView.arrowDirection]; |
| 1617 | + transform = CGAffineTransformScale(transform, 0, 0); |
| 1618 | + containerView.transform = transform; |
| 1619 | + } |
| 1620 | + |
1573 | 1621 | [UIView animateWithDuration:WY_POPOVER_DEFAULT_ANIMATION_DURATION animations:^{ |
1574 | 1622 | containerView.alpha = 1; |
| 1623 | + containerView.transform = CGAffineTransformIdentity; |
1575 | 1624 | } completion:^(BOOL finished) { |
1576 | 1625 | if ([viewController isKindOfClass:[UINavigationController class]] == NO) |
1577 | 1626 | { |
@@ -1614,6 +1663,63 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr |
1614 | 1663 | } |
1615 | 1664 | } |
1616 | 1665 |
|
| 1666 | +- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item |
| 1667 | + permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections |
| 1668 | + animated:(BOOL)aAnimated |
| 1669 | + options:(WYPopoverAnimationOptions)aOptions |
| 1670 | +{ |
| 1671 | + barButtonItem = item; |
| 1672 | + UIView *itemView = [barButtonItem valueForKey:@"view"]; |
| 1673 | + arrowDirections = WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp; |
| 1674 | + [self presentPopoverFromRect:itemView.bounds |
| 1675 | + inView:itemView |
| 1676 | + permittedArrowDirections:arrowDirections |
| 1677 | + animated:aAnimated |
| 1678 | + options:aOptions]; |
| 1679 | +} |
| 1680 | + |
| 1681 | +- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated |
| 1682 | + options:(WYPopoverAnimationOptions)aOptions |
| 1683 | +{ |
| 1684 | + [self presentPopoverFromRect:CGRectZero |
| 1685 | + inView:nil |
| 1686 | + permittedArrowDirections:WYPopoverArrowDirectionNone |
| 1687 | + animated:aAnimated |
| 1688 | + options:aOptions]; |
| 1689 | +} |
| 1690 | + |
| 1691 | +- (CGAffineTransform)transformTranslateForArrowDirection:(WYPopoverArrowDirection)arrowDirection |
| 1692 | +{ |
| 1693 | + CGAffineTransform transform = CGAffineTransformIdentity; |
| 1694 | + |
| 1695 | + if (containerView.arrowHeight > 0) |
| 1696 | + { |
| 1697 | + CGSize containerViewSize = containerView.frame.size; |
| 1698 | + |
| 1699 | + if (arrowDirection == WYPopoverArrowDirectionDown) |
| 1700 | + { |
| 1701 | + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.arrowOffset, containerViewSize.height / 2); |
| 1702 | + } |
| 1703 | + |
| 1704 | + if (arrowDirection == WYPopoverArrowDirectionUp) |
| 1705 | + { |
| 1706 | + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.arrowOffset, -containerViewSize.height / 2); |
| 1707 | + } |
| 1708 | + |
| 1709 | + if (arrowDirection == WYPopoverArrowDirectionRight) |
| 1710 | + { |
| 1711 | + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, containerView.frame.size.width / 2, containerView.arrowOffset); |
| 1712 | + } |
| 1713 | + |
| 1714 | + if (arrowDirection == WYPopoverArrowDirectionLeft) |
| 1715 | + { |
| 1716 | + transform = CGAffineTransformTranslate(CGAffineTransformIdentity, -containerView.frame.size.width / 2, containerView.arrowOffset); |
| 1717 | + } |
| 1718 | + } |
| 1719 | + |
| 1720 | + return transform; |
| 1721 | +} |
| 1722 | + |
1617 | 1723 | - (void)setPopoverNavigationBarBackgroundImage |
1618 | 1724 | { |
1619 | 1725 | if (wantsDefaultContentAppearance == NO && [viewController isKindOfClass:[UINavigationController class]]) |
@@ -1644,19 +1750,6 @@ - (void)setPopoverNavigationBarBackgroundImage |
1644 | 1750 | } |
1645 | 1751 | } |
1646 | 1752 |
|
1647 | | -- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(WYPopoverArrowDirection)arrowDirections animated:(BOOL)aAnimated |
1648 | | -{ |
1649 | | - barButtonItem = item; |
1650 | | - UIView *itemView = [barButtonItem valueForKey:@"view"]; |
1651 | | - arrowDirections = WYPopoverArrowDirectionDown | WYPopoverArrowDirectionUp; |
1652 | | - [self presentPopoverFromRect:itemView.bounds inView:itemView permittedArrowDirections:arrowDirections animated:aAnimated]; |
1653 | | -} |
1654 | | - |
1655 | | -- (void)presentPopoverAsDialogAnimated:(BOOL)aAnimated |
1656 | | -{ |
1657 | | - [self presentPopoverFromRect:CGRectZero inView:nil permittedArrowDirections:WYPopoverArrowDirectionNone animated:aAnimated]; |
1658 | | -} |
1659 | | - |
1660 | 1753 | - (void)positionPopover |
1661 | 1754 | { |
1662 | 1755 | CGSize contentViewSize = self.contentSizeForViewInPopover; |
|
0 commit comments