我想要一个按钮来触发以下操作。单击时,它应该将我的徽标向上推出并移出视图并将其删除。当它再次被点击时,它应该做相反的事情。这意味着图像被创建并被推回视图中。我正在使用故事板来设置我的界面。我的问题是我无法触发动画。在下面发布我的代码:
在 TableViewController.h
@interface TableViewController : UITableViewController{
BOOL status;
}
@property (weak, nonatomic) IBOutlet UIImageView *animateLogo;
@property (weak, nonatomic) IBOutlet UIButton *button;
- (IBAction)onClick:(id)sender;
- (void)showHideView;
@end
在 TableViewController.m
@synthesize animateLogo, button;
- (void)viewDidLoad{
[super viewDidLoad];
status = YES;
}
- (IBAction)onClick:(id)sender{
[self showHideView];
}
if(status){
[UIView
animateWithDuration:1.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, -animateLogo.frame.size.height)];
}
completion:^(BOOL completed) {}
];
status = NO;
[button setTitle:@"Show" forState:UIControlStateNormal];
}
else{
[UIView
animateWithDuration:1.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];
}
completion:^(BOOL completed) {}
];
status = YES;
[button setTitle:@"Hide" forState:UIControlStateNormal];
}
}
编辑:
如果我以编程方式对 UIImageView 进行编码,则动画正在工作。所以问题出在故事板上。我更喜欢让这个与故事板一起工作,这样我可以更好地了解布局。
UIImage *test = [UIImage imageNamed:@"logo.png"];
animateLogo = [[UIImageView alloc] initWithImage:test];
[self.view addSubview:animateLogo];
[animateLogo setFrame:CGRectOffset([animateLogo frame], 0, animateLogo.frame.size.height)];