最近在看一些开源项目,其中有一个弹出菜单QuadCurveMenu觉得挺不错,可惜只可以向右上角弹出菜单,于是就修改了下,实现了八个方向的弹出菜单,现在发上来供大家批评指正。
-
-
-
-
-
-
-
-
-
#import<UIKit/UIKit.h>
-
#import"QuadCurveMenuItem.h"
-
-
@protocolQuadCurveMenuDelegate;
-
-
-
-
-
-
-
-
-
-
typedefenum
-
{
-
QuadCurveMenuTypeUpAndRight=0,
-
QuadCurveMenuTypeUpAndLeft,
-
QuadCurveMenuTypeDownAndRight,
-
QuadCurveMenuTypeDownAndLeft,
-
QuadCurveMenuTypeUp,
-
QuadCurveMenuTypeDown,
-
QuadCurveMenuTypeLeft,
-
QuadCurveMenuTypeRight,
-
QuadCurveMenuTypeDefault=QuadCurveMenuTypeUpAndRight
-
}QuadCureMenuType;
-
-
@interfaceQuadCurveMenu:UIView<QuadCurveMenuItemDelegate>
-
{
-
NSArray*_menusArray;
-
int_flag;
-
NSTimer*_timer;
-
QuadCurveMenuItem*_addButton;
-
QuadCureMenuType_type;
-
id<QuadCurveMenuDelegate>_delegate;
-
-
CGPoint_startPoint;
-
-
}
-
@property(nonatomic,copy)NSArray*menusArray;
-
@property(nonatomic)QuadCureMenuTypetype;
-
@property(nonatomic,getter=isExpanding)BOOLexpanding;
-
@property(nonatomic,assign)id<QuadCurveMenuDelegate>delegate;
-
-(id)initWithFrame:(CGRect)framemenus:(NSArray*)aMenusArray;
-
-(void)setType:(QuadCureMenuType)type;
-
-(void)setStartPoint:(CGPoint)startpoint;
-
@end
-
-
@protocolQuadCurveMenuDelegate<NSObject>
-
-(void)quadCurveMenu:(QuadCurveMenu*)menudidSelectIndex:(NSInteger)idx;
-
@end
-
-
-
-
-
-
-
-
-
#import"QuadCurveMenu.h"
-
#import<QuartzCore/QuartzCore.h>
-
-
#defineNEARRADIUS130.0f
-
#defineENDRADIUS140.0f
-
#defineFARRADIUS160.0f
-
#defineBETWEENADIUS50.0f
-
#defineSTARTPOINTCGPointMake(100,130)
-
#defineTIMEOFFSET0.05f
-
-
-
@interfaceQuadCurveMenu()
-
-(void)_expand;
-
-(void)_close;
-
-(CAAnimationGroup*)_blowupAnimationAtPoint:(CGPoint)p;
-
-(CAAnimationGroup*)_shrinkAnimationAtPoint:(CGPoint)p;
-
@end
-
-
@implementationQuadCurveMenu
-
@synthesizeexpanding=_expanding;
-
@synthesizedelegate=_delegate;
-
@synthesizemenusArray=_menusArray;
-
@synthesizetype=_type;
-
-
-
#pragmamark-initialization&cleaningup
-
-(id)initWithFrame:(CGRect)framemenus:(NSArray*)aMenusArray
-
{
-
self=[superinitWithFrame:frame];
-
if(self){
-
self.backgroundColor=[UIColorclearColor];
-
-
_startPoint=STARTPOINT;
-
_menusArray=[aMenusArraycopy];
-
-
-
intcount=[_menusArraycount];
-
for(inti=0;i<count;i++)
-
{
-
QuadCurveMenuItem*item=[_menusArrayobjectAtIndex:i];
-
item.tag=1000+i;
-
item.startPoint=STARTPOINT;
-
item.endPoint=CGPointMake(_startPoint.x+ENDRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-ENDRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.nearPoint=CGPointMake(_startPoint.x+NEARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-NEARRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.farPoint=CGPointMake(_startPoint.x+FARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-FARRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.center=item.startPoint;
-
item.delegate=self;
-
[selfaddSubview:item];
-
}
-
-
-
_addButton=[[QuadCurveMenuItemalloc]initWithImage:[UIImageimageNamed:@"story-add-button.png"]
-
highlightedImage:[UIImageimageNamed:@"story-add-button-pressed.png"]
-
ContentImage:[UIImageimageNamed:@"story-add-plus.png"]
-
highlightedContentImage:[UIImageimageNamed:@"story-add-plus-pressed.png"]];
-
_addButton.delegate=self;
-
_addButton.center=_startPoint;
-
[selfaddSubview:_addButton];
-
}
-
returnself;
-
}
-
-
-
-(void)setType:(QuadCureMenuType)type
-
{
-
_type=type;
-
intdx=1;
-
intdy=1;
-
BOOLisTwoDirctions=YES;
-
-
if(_menusArray!=nil){
-
-
switch(type){
-
caseQuadCurveMenuTypeUpAndRight:
-
break;
-
caseQuadCurveMenuTypeUpAndLeft:
-
dx=-1;
-
break;
-
caseQuadCurveMenuTypeDownAndRight:
-
dy=-1;
-
break;
-
caseQuadCurveMenuTypeDownAndLeft:
-
dy=dx=-1;
-
break;
-
caseQuadCurveMenuTypeUp:
-
isTwoDirctions=NO;dx=0;dy=-1;
-
break;
-
caseQuadCurveMenuTypeDown:
-
isTwoDirctions=NO;dx=0;dy=1;
-
break;
-
caseQuadCurveMenuTypeLeft:
-
isTwoDirctions=NO;dx=-1;dy=0;
-
break;
-
caseQuadCurveMenuTypeRight:
-
isTwoDirctions=NO;dx=1;dy=0;
-
default:
-
break;
-
}
-
-
intcount=[_menusArraycount];
-
for(inti=0;i<count;i++)
-
{
-
QuadCurveMenuItem*item=[_menusArrayobjectAtIndex:i];
-
item.startPoint=_startPoint;
-
if(isTwoDirctions){
-
item.endPoint=CGPointMake(_startPoint.x+dx*ENDRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-dy*ENDRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.nearPoint=CGPointMake(_startPoint.x+dx*NEARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-dy*NEARRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.farPoint=CGPointMake(_startPoint.x+dx*FARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-dy*FARRADIUS*cosf(i*M_PI_2/(count-1)));
-
}else
-
{
-
item.endPoint=CGPointMake(_startPoint.x+dx*i*BETWEENADIUS,_startPoint.y+dy*i*BETWEENADIUS);
-
item.nearPoint=CGPointMake(_startPoint.x+dx*i*(BETWEENADIUS-15),_startPoint.y+dy*i*(BETWEENADIUS-15));
-
item.farPoint=CGPointMake(_startPoint.x+dx*i*(BETWEENADIUS+20),_startPoint.y+dy*i*(BETWEENADIUS+20));
-
-
}
-
item.center=item.startPoint;
-
-
}
-
-
}
-
}
-
-
-(void)setStartPoint:(CGPoint)startpoint
-
{
-
_startPoint=startpoint;
-
_addButton.center=_startPoint;
-
[selfsetType:_type];
-
};
-
-
-(void)dealloc
-
{
-
[_addButtonrelease];
-
[_menusArrayrelease];
-
[superdealloc];
-
}
-
-
-
#pragmamark-UIView'smethods
-
-(BOOL)pointInside:(CGPoint)pointwithEvent:(UIEvent*)event
-
{
-
-
-
if(YES==_expanding)
-
{
-
returnYES;
-
}
-
else
-
{
-
returnCGRectContainsPoint(_addButton.frame,point);
-
}
-
}
-
-
-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event
-
{
-
self.expanding=!self.isExpanding;
-
}
-
-
#pragmamark-QuadCurveMenuItemdelegates
-
-(void)quadCurveMenuItemTouchesBegan:(QuadCurveMenuItem*)item
-
{
-
if(item==_addButton)
-
{
-
self.expanding=!self.isExpanding;
-
}
-
}
-
-(void)quadCurveMenuItemTouchesEnd:(QuadCurveMenuItem*)item
-
{
-
-
if(item==_addButton)
-
{
-
return;
-
}
-
-
CAAnimationGroup*blowup=[self_blowupAnimationAtPoint:item.center];
-
[item.layeraddAnimation:blowupforKey:@"blowup"];
-
item.center=item.startPoint;
-
-
-
for(inti=0;i<[_menusArraycount];i++)
-
{
-
QuadCurveMenuItem*otherItem=[_menusArrayobjectAtIndex:i];
-
CAAnimationGroup*shrink=[self_shrinkAnimationAtPoint:otherItem.center];
-
if(otherItem.tag==item.tag){
-
continue;
-
}
-
[otherItem.layeraddAnimation:shrinkforKey:@"shrink"];
-
-
otherItem.center=otherItem.startPoint;
-
}
-
_expanding=NO;
-
-
-
floatangle=self.isExpanding?-M_PI_4:0.0f;
-
[UIViewanimateWithDuration:0.2fanimations:^{
-
_addButton.transform=CGAffineTransformMakeRotation(angle);
-
}];
-
-
if([_delegaterespondsToSelector:@selector(quadCurveMenu:didSelectIndex:)])
-
{
-
[_delegatequadCurveMenu:selfdidSelectIndex:item.tag-1000];
-
}
-
}
-
-
#pragmamark-instantmethods
-
-(void)setMenusArray:(NSArray*)aMenusArray
-
{
-
if(aMenusArray==_menusArray)
-
{
-
return;
-
}
-
[_menusArrayrelease];
-
_menusArray=[aMenusArraycopy];
-
-
-
-
for(UIView*vinself.subviews)
-
{
-
if(v.tag>=1000)
-
{
-
[vremoveFromSuperview];
-
}
-
}
-
-
-
intcount=[_menusArraycount];
-
for(inti=0;i<count;i++)
-
{
-
QuadCurveMenuItem*item=[_menusArrayobjectAtIndex:i];
-
item.tag=1000+i;
-
item.startPoint=_startPoint;
-
item.endPoint=CGPointMake(_startPoint.x+ENDRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-ENDRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.nearPoint=CGPointMake(_startPoint.x+NEARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-NEARRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.farPoint=CGPointMake(_startPoint.x+FARRADIUS*sinf(i*M_PI_2/(count-1)),_startPoint.y-FARRADIUS*cosf(i*M_PI_2/(count-1)));
-
item.center=item.startPoint;
-
item.delegate=self;
-
[selfaddSubview:item];
-
}
-
}
-
-(BOOL)isExpanding
-
{
-
return_expanding;
-
}
-
-(void)setExpanding:(BOOL)expanding
-
{
-
_expanding=expanding;
-
-
-
floatangle=self.isExpanding?-M_PI_4:0.0f;
-
[UIViewanimateWithDuration:0.2fanimations:^{
-
_addButton.transform=CGAffineTransformMakeRotation(angle);
-
}];
-
-
-
if(!_timer)
-
{
-
_flag=self.isExpanding?0:5;
-
SELselector=self.isExpanding?@selector(_expand):@selector(_close);
-
_timer=[[NSTimerscheduledTimerWithTimeInterval:TIMEOFFSETtarget:selfselector:selectoruserInfo:nilrepeats:YES]retain];
-
}
-
}
-
#pragmamark-privatemethods
-
-(void)_expand
-
{
-
if(_flag==6)
-
{
-
[_timerinvalidate];
-
[_timerrelease];
-
_timer=nil;
-
return;
-
}
-
-
inttag=1000+_flag;
-
QuadCurveMenuItem*item=(QuadCurveMenuItem*)[selfviewWithTag:tag];
-
-
CAKeyframeAnimation*rotateAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"transform.rotation.z"];
-
rotateAnimation.values=[NSArrayarrayWithObjects:[NSNumbernumberWithFloat:M_PI],[NSNumbernumberWithFloat:0.0f],nil];
-
rotateAnimation.duration=0.5f;
-
rotateAnimation.keyTimes=[NSArrayarrayWithObjects:
-
[NSNumbernumberWithFloat:.3],
-
[NSNumbernumberWithFloat:.4],nil];
-
-
CAKeyframeAnimation*positionAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position"];
-
positionAnimation.duration=0.5f;
-
CGMutablePathRefpath=CGPathCreateMutable();
-
CGPathMoveToPoint(path,NULL,item.startPoint.x,item.startPoint.y);
-
CGPathAddLineToPoint(path,NULL,item.farPoint.x,item.farPoint.y);
-
CGPathAddLineToPoint(path,NULL,item.nearPoint.x,item.nearPoint.y);
-
CGPathAddLineToPoint(path,NULL,item.endPoint.x,item.endPoint.y);
-
positionAnimation.path=path;
-
CGPathRelease(path);
-
-
CAAnimationGroup*animationgroup=[CAAnimationGroupanimation];
-
animationgroup.animations=[NSArrayarrayWithObjects:positionAnimation,rotateAnimation,nil];
-
animationgroup.duration=0.5f;
-
animationgroup.fillMode=kCAFillModeForwards;
-
animationgroup.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];
-
[item.layeraddAnimation:animationgroupforKey:@"Expand"];
-
item.center=item.endPoint;
-
-
_flag++;
-
-
}
-
-
-(void)_close
-
{
-
if(_flag==-1)
-
{
-
[_timerinvalidate];
-
[_timerrelease];
-
_timer=nil;
-
return;
-
}
-
-
inttag=1000+_flag;
-
QuadCurveMenuItem*item=(QuadCurveMenuItem*)[selfviewWithTag:tag];
-
-
CAKeyframeAnimation*rotateAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"transform.rotation.z"];
-
rotateAnimation.values=[NSArrayarrayWithObjects:[NSNumbernumberWithFloat:0.0f],[NSNumbernumberWithFloat:M_PI*2],[NSNumbernumberWithFloat:0.0f],nil];
-
rotateAnimation.duration=0.5f;
-
rotateAnimation.keyTimes=[NSArrayarrayWithObjects:
-
[NSNumbernumberWithFloat:.0],
-
[NSNumbernumberWithFloat:.4],
-
[NSNumbernumberWithFloat:.5],nil];
-
-
CAKeyframeAnimation*positionAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position"];
-
positionAnimation.duration=0.5f;
-
CGMutablePathRefpath=CGPathCreateMutable();
-
CGPathMoveToPoint(path,NULL,item.endPoint.x,item.endPoint.y);
-
CGPathAddLineToPoint(path,NULL,item.farPoint.x,item.farPoint.y);
-
CGPathAddLineToPoint(path,NULL,item.startPoint.x,item.startPoint.y);
-
positionAnimation.path=path;
-
CGPathRelease(path);
-
-
CAAnimationGroup*animationgroup=[CAAnimationGroupanimation];
-
animationgroup.animations=[NSArrayarrayWithObjects:positionAnimation,rotateAnimation,nil];
-
animationgroup.duration=0.5f;
-
animationgroup.fillMode=kCAFillModeForwards;
-
animationgroup.timingFunction=[CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseIn];
-
[item.layeraddAnimation:animationgroupforKey:@"Close"];
-
item.center=item.startPoint;
-
_flag--;
-
}
-
-
-(CAAnimationGroup*)_blowupAnimationAtPoint:(CGPoint)p
-
{
-
CAKeyframeAnimation*positionAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position"];
-
positionAnimation.values=[NSArrayarrayWithObjects:[NSValuevalueWithCGPoint:p],nil];
-
positionAnimation.keyTimes=[NSArrayarrayWithObjects:[NSNumbernumberWithFloat:.3],nil];
-
-
CABasicAnimation*scaleAnimation=[CABasicAnimationanimationWithKeyPath:@"transform"];
-
scaleAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(3,3,1)];
-
-
CABasicAnimation*opacityAnimation=[CABasicAnimationanimationWithKeyPath:@"opacity"];
-
opacityAnimation.toValue=[NSNumbernumberWithFloat:0.0f];
-
-
CAAnimationGroup*animationgroup=[CAAnimationGroupanimation];
-
animationgroup.animations=[NSArrayarrayWithObjects:positionAnimation,scaleAnimation,opacityAnimation,nil];
-
animationgroup.duration=0.3f;
-
animationgroup.fillMode=kCAFillModeForwards;
-
-
returnanimationgroup;
-
}
-
-
-(CAAnimationGroup*)_shrinkAnimationAtPoint:(CGPoint)p
-
{
-
CAKeyframeAnimation*positionAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position"];
-
positionAnimation.values=[NSArrayarrayWithObjects:[NSValuevalueWithCGPoint:p],nil];
-
positionAnimation.keyTimes=[NSArrayarrayWithObjects:[NSNumbernumberWithFloat:.3],nil];
-
-
CABasicAnimation*scaleAnimation=[CABasicAnimationanimationWithKeyPath:@"transform"];
-
scaleAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(.01,.01,1)];
-
-
CABasicAnimation*opacityAnimation=[CABasicAnimationanimationWithKeyPath:@"opacity"];
-
opacityAnimation.toValue=[NSNumbernumberWithFloat:0.0f];
-
-
CAAnimationGroup*animationgroup=[CAAnimationGroupanimation];
-
animationgroup.animations=[NSArrayarrayWithObjects:positionAnimation,scaleAnimation,opacityAnimation,nil];
-
animationgroup.duration=0.3f;
-
animationgroup.fillMode=kCAFillModeForwards;
-
-
returnanimationgroup;
-
}
-
-
-
@end
运行截图:
DEMO下载地址:http://download.csdn.net/detail/toss156/4164935
分享到:
相关推荐
但是dhtmlXTree不能满足"每个节点都有各自的URL地址,单击不同的节点框架页的右侧跳转到该节点所对应的URL"这点需求,因次想到了对dhtmlXTree进行一个小的扩展,即在其节点对象原有属性的基础上,再添加两个扩展属性...
易语言弹出轨迹菜单源码,弹出轨迹菜单,弹出轨迹菜单_,取菜单_,取鼠标位置_,取子菜单句柄_,清除菜单_
【IOS】扩展QuadCurveMenu,实现了八个方向上的弹出菜单
QuadCurveMenu, 路径 2.0菜单( 可以配置,可以扩展和可以组合) QuadCurveMenu是一个菜单,与的菜单menu菜单story菜单的菜单菜单相同。 这是一个 fork的 AwesomeMenu的。 我提出了请求请求,而这不是原始作者想要创建...
demo 博文链接:https://tianqiushi.iteye.com/blog/2103791
看完此文后您将能够创建一个由选择内容指定弹出项的动态菜单。 setp1.创建一个rcp工程,模板使用有一个view的 step2.创建popupMenu step2_1.新建类Action1: step2_2.添加扩展点: 好的step2已经结束了,现在...
一机双屏,一机多屏,web前端打开新页面到扩展屏幕demo,通过presentation API打开窗口(谷歌浏览器版本) PS:需采用服务器方式启动index项目,请勿双击谷歌浏览器直接打开
Js实现旋转导航菜单,r半径,dv偏移量,w图片宽度,x菜单横坐标,y菜单纵坐标,pn菜单图片数量,当图片旋转到圆的正面时,传入当前... 制作这款旋转菜单用到了圆形几何知识,由此您也可扩展出扇形菜单、多边形菜单等。
jQuery+css3实现的大幅面可扩展子导航菜单效果(弹出内容可自定义).zip
本文实例讲述了jquery实现...本弹性菜单可扩展性强,实际上不光可以做成菜单,也可布局一些图文混排的内容或一段视频,总之被弹出的内容是在一段Div内,怎么布置就看你的了。 运行效果截图如下: 在线演示地址如下: ...
菜单项弹出动画;背景模糊效果 注意:在gradle中开启renderscript,支持模糊效果(高斯模糊也叫毛玻璃) defaultConfig { applicationId "com.dsy.plusmenu" ... renderscriptTargetApi 25 ...
原生弹出框alert由于样式等问题被业界人士所讨厌。本例是基于jQuery进行扩展写出,alert和confirm(带确认和取消按钮并能触发回调函数)
VC Windows Shell扩展,设计 制作 上下文菜单扩展,响应右键消息菜单,当用户点击我们添加的菜单项时该方法将被调用。将生成的菜单插入到shell上下文菜单中,返回插入的菜单数,一定要返回正确,包括生成的父菜单也...
React本机弹出菜单 适用于Android,iOS和(非正式)UWP和react-native-web的React Native的可扩展弹出菜单组件。 特征: 易于使用的弹出/上下文菜单多种模式:动画,不动画,从底部滑动或弹出框默认情况下打开和关闭...
扩展弹出框接口,自定义弹出位置和消失时间
扩展SlidingMenu实现QQ5.0侧滑菜单
右键扩展菜单管理器 右键扩展菜单管理器 右键扩展菜单管理器 右键扩展菜单管理器
可扩展、可单独分离使用的弹出式评论列表,一般用于查看全部评论,仅引入了Masonry做布局 1、可扩展、可单独分离使用的弹出式评论列表,一般用于查看全部评论; 2、键盘弹出评论输入,自适应文字高度; 3、...
或者仅中键按下弹出菜单,或者鼠标移动弹出菜单. 可以指定"不同的鼠标消息弹出不同的菜单". 可以将托盘通知消息转发到指定的窗口并且可以动态改变, 但是接收通知消息的窗口需要定义通知消息的处理函数.