【发布时间】:2015-12-21 06:52:13
【问题描述】:
嗨,我是 iOS 新手,我在 MainViewController 的底部添加了一个 UIView。
当我点击一个按钮时,UIView 使用UIView 动画显示为“UIAction sheet”。
为此,我尝试了下面的代码,但是当我点击按钮时动画不适用。
请帮助我。
我的代码:-
#import "AnimationUIview.h"
@interface AnimationUIview ()
{
UIView * firstView;
NSLayoutConstraint * Bottom;
}
@end
@implementation AnimationUIview
- (void)viewDidLoad {
[super viewDidLoad];
firstView = [[UIView alloc] init];
firstView.backgroundColor = [UIColor lightGrayColor];
firstView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:firstView];
NSDictionary * views = NSDictionaryOfVariableBindings(firstView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[firstView]-0-|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[firstView(100)]" options:0 metrics:nil views:views]];
Bottom = [NSLayoutConstraint constraintWithItem:firstView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1
constant:80];
[self.view addConstraint:Bottom];
}
- (IBAction)buttonAction:(id)sender {
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
Bottom.constant = -10;
}
completion:nil];
}
@end
【问题讨论】:
标签: ios iphone animation uiview uiactionsheet