让菜单出现,向用户展示美丽的易于访问的按钮,而无需从他们想要的位置移开。
注意:KLExpandingSelect 面向 iPhone/iPad/iPod Touch 的纵向模式使用。
查看演示 由于我的电脑运行速度慢,请原谅图形错误和卡顿。
将包含的 KLExpandingSelect.h, KLExpandingSelect.m
文件拖放到您的项目中。然后,在 链接二进制与库 下包含以下框架
导入所需文件,并声明您的控制器,符合 KLExpandingSelect 数据源和代理规范。
#import "KLExpandingSelect.h"
@interface KLRootViewController : UIViewController <KLExpandingSelectDataSource, KLExpandingSelectDelegate>
初始化控件
// Configure the Expander Select and add to view controllers view.
self.expandingSelect = [[KLExpandingSelect alloc] initWithDelegate: self
dataSource: self];
[self.view setExpandingSelect:self.expandingSelect];
[self.view addSubview: self.expandingSelect];
实现数据源所需的方法
- (NSInteger)expandingSelector:(id) expandingSelect numberOfRowsInSection:(NSInteger)section{
return [self.selectorData count];
}
- (KLExpandingPetal *)expandingSelector:(id) expandingSelect itemForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* dictForPetal = [self.selectorData objectAtIndex:indexPath.row];
NSString* imageName = [dictForPetal objectForKey:@"image"];
KLExpandingPetal* petal = [[KLExpandingPetal alloc] initWithImage:[UIImage imageNamed:imageName]];
return petal;
}
实现可选的代理方法,以在选中新项目时通知
// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
- (NSIndexPath *)expandingSelector:(id)expandingSelect willSelectItemAtIndexPath:(NSIndexPath *)indexPath;
// Called after the user changes the selection.
- (void)expandingSelector:(id)expandingSelect didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
//Called after the animations have completed
- (void)expandingSelector:(id)expandingSelect didFinishExpandingAtPoint:(CGPoint) point;
- (void)expandingSelector:(id)expandingSelect didFinishCollapsingAtPoint:(CGPoint) point;
- (void)expandingSelector:(id)expandingSelect didFinishExpandingPetal: (KLExpandingPetal*) petal;
- (void)expandingSelector:(id)expandingSelect didFinishCollapsingPetal: (KLExpandingPetal*) petal;
可以通过修改 KLExpandingSelect.m
中的常数来调整可视化外观
//Petal settings
#define kPetalHeight 80
#define kPetalWidth 60
#define kPetalShadowColor [UIColor darkGrayColor]
#define kPetalShadowOffset CGSizeMake(0, 3)
#define kPetalShadowOpacity 0.6
#define kPetalShadowRadius 4
#define kPetalAlpha 0.96
//Animation Settings
#define KAnimationFanOutDegrees 360.0 //Amount for the control to fan out 360 = fully fanned out, 180 = half fanned out
#define kAnimationGrowDuration 0.3
#define kAnimationRotateDuration 0.3
#define kAnimationPetalSpread 1.003 //A tuning parameter for determining how crowded petals are with respect to eachother
#define kAnimationPetalDelay 0.1 //The amount of time between animating each petal
#define kAnimationPetalMinScale 0.001 //Scale of the item at its smallest (i.e 0.01 is 1/100th its original size
#define kAnimationPetalMaxScale 1000 //Scale of the item at its largest (relative to on kAnimationPetalMinScale)
//Customize the layout of the control
#define kDefaultRotation 0.0 //Degrees to rotate the control
#define kDefaultHeight 2*kPetalHeight*kAnimationPetalSpread //The height of the control upon full expansion
#define kDefaultWidth kDefaultHeight //The width of the control upon full expansion
#define kDefaultTopMargin kPetalHeight*kAnimationPetalSpread //Amount of space to reserve the top to ensure that the control doesnt get drawn off screen
#define kDefaultRightMargin kPetalHeight*kAnimationPetalSpread //Amount of space to reserve the right to ensure that the control doesnt get drawn off screen
#define kDefaultBottomMargin kPetalHeight*kAnimationPetalSpread //Amount of space to reserve the bottom to ensure that the control doesnt get drawn off screen
#define kDefaultLeftMargin kPetalHeight*kAnimationPetalSpread //Amount of space to reserve the left to ensure that the control doesnt get drawn off screen
#define kDefaultRasterizationScale 5.0
#define kLongPressDuration 1.0 //The length of time before a touch is registered and the control appears on the parent view
版权(c)2012 Kieran Lafferty
特此授予任何人免费获取此软件及相关文档文件(“软件”)的副本的权利,不受任何限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向获得软件的人提供软件,前提是遵守以下条件
上述版权声明和本许可声明必须包含在软件的所有副本或实质部分中。
软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的还是暗示的,包括但不限于适销性、针对特定目的适用性和非侵权性保证。在任何事件中,作者或版权所有者不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他诉讼,源于、产生于或与该软件或软件的使用或其他处理有关。