【问题标题】:Ios Animation of UIImageView with Constraints带约束的 UIImageView 的 iOS 动画
【发布时间】:2016-02-23 14:17:49
【问题描述】:

我有一个 UIImageView,我使用对齐中心 X 和对齐中心 Y 约束将其放置在屏幕中心。我希望图像与动画一起移动到屏幕顶部,保持容器中的水平对齐并有 20 的空间当我按下按钮时从顶部开始。以编程方式删除对齐中心 Y 约束并添加顶部空间约束是一个好方法吗?

【问题讨论】:

标签: ios objective-c animation uiimageview autolayout


【解决方案1】:

使用 UIScreen 类和您的视图高度动态计算常量。

@interface ViewController : UIViewController

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *centerYConstraint;
@property (nonatomic, weak) IBOutlet UIView *myView;

- (IBAction)moveView:(id)sender;

@end


- (IBAction)moveView:(id)sender
{
     self.centerYConstraint.constant = 20.0 + (self.myView.frame.size.height * 0.5) - ([UIScreen mainScreen].bounds.size.height * 0.5);
    [UIView animateWithDuration:1.0 animations:^{
        [self.view layoutIfNeeded];
    }];
}

您可以在此处下载代码 (http://cl.ly/3l1B0k1L0h1C)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 2017-07-31
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多