ContextMenu.iOS 1.1.0

ContextMenu.iOS 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 Apache 2
发布最后发布2015年11月

Maksim UsenkoKoloda 维护。



Context-Menu.iOS

您可以将炫酷的动画上下文菜单轻松添加到您的应用程序中。

Yalantis 制作

查看这个 dribbble项目中

查看这个 Behance项目

ContextMenu

用法

欢迎您查看示例文件夹中的项目样例,以了解完整的操作。

  • 将YALContextMenu文件夹添加到您的项目中。
  • 在您的视图控制器中添加 #import “YALContextMenuTableView.h”
  • 创建自定义UITableViewCell,其中包含用于旋转动画的UIView属性,以及用于淡出动画的UIView属性。
  • 您的自定义cell应实现YALContextMenuCell协议
@protocol YALContextMenuCell <NSObject>

- (UIView *)animatedIcon;
- (UIView *)animatedContent;

@end
  • 使用以下代码示例启动菜单
- (IBAction)presentMenuButtonTapped:(UIBarButtonItem *)sender {
// init YALContextMenuTableView tableView
if (!self.contextMenuTableView) {
self.contextMenuTableView = [[YALContextMenuTableView alloc]initWithTableViewDelegateDataSource:self];
self.contextMenuTableView.animationDuration = 0.15;
//optional - implement custom YALContextMenuTableView custom protocol
self.contextMenuTableView.yalDelegate = self;
//optional - implement menu items layout
self.contextMenuTableView.menuItemsSide = Right;
self.contextMenuTableView.menuItemsAppearanceDirection = FromTopToBottom;

//register nib
UINib *cellNib = [UINib nibWithNibName:@"ContextMenuCell" bundle:nil];
[self.contextMenuTableView registerNib:cellNib forCellReuseIdentifier:@"contextMenuCellReuseId"];
}

// it is better to use this method only for proper animation
[self.contextMenuTableView showInView:self.navigationController.view withEdgeInsets:UIEdgeInsetsZero animated:YES];
}
  • 使用默认的UITableViewDataSource方法来进行额外的设置和单元格的自定义。
  • 在旋转动画开始之前调用updateAlongsideRotation方法,或在旋转动画完成后或在UIViewControllerTransitionCoordinator的animateAlongsideTransition块中调用reloadData方法,以进行适当的旋转动画。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
//should be called after rotation animation completed
[self.contextMenuTableView reloadData];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

[self.contextMenuTableView updateAlongsideRotation];
}

- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {

[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];


[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
//should be called after rotation animation completed
[self.contextMenuTableView reloadData];
}];
[self.contextMenuTableView updateAlongsideRotation];

}

自定义

为了自定义菜单项的边侧位置,您可以指定一个'menuItemsSide'属性。当将其设置为'Right'时,第一个单元格将从右向左打开,被选中的单元格将相反关闭。当将其设置为'Left'时,第一个单元格将从左向右打开,反向关闭被选中的单元格。默认 - Right。

此外,为了自定义菜单项的显示方向,您可以指定'menuItemsAppearanceDirection'属性。默认 - FromTopToBottom。

为了自定义单元格,您可以在动画图标中设置自己的自定义可绘制的。实际上,单元格的设计和布局完全由您决定。

animationDuration用于动画速度,单位为秒。

兼容性

iOS 7, iOS 8, iOS 9

版本:1.1.0

许可证

版权所有 2015,Yalantis

根据Apache许可证版本2.0(“许可证”);除非您遵守该许可证,否则不得使用此文件。您可以在[此处](https://apache.ac.cn/licenses/LICENSE-2.0)获得许可证副本。

https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则根据本许可发布的软件“现状”提供,不提供任何形式的明示或暗示保证。有关许可下授权和限制的具体语言,请参阅许可协议。