Ios 带有长按手势的弹出式菜单
我对ios和核心动画都是新手,所以我正在做一些测试来适应它。 我有一个菜单,我正试图通过做一个长按手势来创建。我希望按钮通过向上设置动画,然后向下设置动画,然后消失。我让出现的部分工作,但我不知道如何使它消失。它也不允许我在UIgestureRecognitzerStateEnded语句中设置imageView的动画。基本上,我有两个问题:Ios 带有长按手势的弹出式菜单,ios,objective-c,Ios,Objective C,我对ios和核心动画都是新手,所以我正在做一些测试来适应它。 我有一个菜单,我正试图通过做一个长按手势来创建。我希望按钮通过向上设置动画,然后向下设置动画,然后消失。我让出现的部分工作,但我不知道如何使它消失。它也不允许我在UIgestureRecognitzerStateEnded语句中设置imageView的动画。基本上,我有两个问题: 释放长按时,如何设置按钮向下移动的动画 我怎么能只做其中一个按钮,而不是每次长按时都出现 这是我的.m.里的东西 -(void)onPress:(UILon
-(void)onPress:(UILongPressGestureRecognizer*)longpress{
CGPoint touchCenter = [longpress locationInView:self.view];
UIImage *plus = [UIImage imageNamed:@"plus"];
imageView = [[UIImageView alloc]initWithImage:plus];
CGRect imageViewFrame = CGRectMake(0, 0, 35, 35);
imageViewFrame.origin = CGPointMake(touchCenter.x - imageViewFrame.size.width / 2.0f, touchCenter.y - imageViewFrame.size.height / 2.0f);
imageView.frame = imageViewFrame;
if (longpress.state == UIGestureRecognizerStateBegan) {
[self.view addSubview:imageView];
[UIView animateWithDuration:0.6 animations:^{
CGAffineTransform moveTrans = CGAffineTransformMakeTranslation(0, -40);
imageView.transform = moveTrans;
}];
NSLog(@"Long press");
return;
}else{
if (longpress.state == UIGestureRecognizerStateEnded || longpress.state == UIGestureRecognizerStateCancelled || longpress.state == UIGestureRecognizerStateFailed) {
[UIView animateWithDuration:0.6 animations:^{
CGAffineTransform moveTrans = CGAffineTransformMakeTranslation(0, 40);
imageView.transform = moveTrans;
NSLog(@"long press done");
}];
}
}
}
还有我的
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : UIViewController<UIGestureRecognizerDelegate>
{
UIImageView *imageView;
CAShapeLayer *layer;
}
@property(nonatomic) float angle;
@property(nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImage *image;
@end
#导入
#进口
@界面ViewController:UIViewController
{
UIImageView*图像视图;
CAShapeLayer*层;
}
@性质(非原子)浮动角;
@属性(非原子,强)UIImageView*imageView;
@属性(非原子,强)UIImage*image;
@结束
我现在知道你想做什么了。但是我修改了你的一些代码:
@interface ViewController ()
@property (strong, nonatomic) UIView *moveView;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *recoginzer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onPress:)];
[self.view addGestureRecognizer:recoginzer];
}
- (void)onPress:(UILongPressGestureRecognizer*)longpress {
CGPoint location = [longpress locationInView:self.view];
if (longpress.state == UIGestureRecognizerStateBegan) {
if (!self.moveView) {
self.moveView = [[UIView alloc] initWithFrame:CGRectMake(location.x, location.y, 100, 100)];
self.moveView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.moveView];
} else {
self.moveView.frame = CGRectMake(location.x, location.y, 100, 100);
}
[UIView animateWithDuration:0.6 animations:^{
CGAffineTransform moveTrans = CGAffineTransformMakeTranslation(0, -40);
self.moveView.transform = moveTrans;
}];
NSLog(@"Long press");
} else if (longpress.state == UIGestureRecognizerStateEnded || longpress.state == UIGestureRecognizerStateCancelled || longpress.state == UIGestureRecognizerStateFailed) {
[UIView animateWithDuration:0.6 animations:^{
CGAffineTransform moveTrans = CGAffineTransformMakeTranslation(0, 40);
self.moveView.transform = moveTrans;
NSLog(@"long press done");
}];
}
}
如果您需要更多帮助,请告诉我。这就是我要寻找的行为,但我如何将其应用于uibutton而不是uiview?@StevenP。只需将按钮添加到该视图中。