1
我是新來的IOS和核心動畫,所以我正在做一些測試,以適應它。 我有一個菜單,我試圖通過做一個長按手勢來創建。我希望按鈕可以通過動畫製作,然後製作動畫,然後消失。我看到部分工作,但我無法弄清楚如何使它消失。它也不會讓我在我的UIGestureRecognizerStateEnded語句中動畫我的imageView。基本上,我有兩個問題:長按菜單彈出菜單
當長按被釋放後,我怎樣才能使按鈕動起來?
我怎樣才能使這些按鈕中的一個,而不是他們每次出現我長按?
下面是我在我的.m
-(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");
}];
}
}
}
和我的.h
#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
這就是我正在尋找的行爲,但我會如何將它應用於uibutton而不是uiview? – Steven07
@StevenP。只需將該按鈕添加到該視圖。 – lancy