我有一个名为logoview的UIView。
[logoview setCenter:CGPointMake(100,100)];
[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
[logoview setCenter:CGPointMake(0, 3232)];
}
completion:^(BOOL finished) {
}];
我正在尝试使用上面的代码为它设置动画。它导致物体每次从顶部角落移动到中心。无论我在动画部分使用什么电线......我都在使用故事板。
我的最终目标是在中心显示徽标。然后像在Skype上一样提升徽标,并在facebook登录时显示登录字段。无论我为什么价值
[logoview setCenter:CGPointMake(0, 3232)];
它只是去了中心。
我也试过了:
[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
[logoview setTransform: CGAffineTransformMakeTranslation(0, -80)];
}
completion:^(BOOL finished) {
}];
它可以解除徽标视图,但它也可以将它略微偏移......让它偏离中心。
整个.m
//
// ViewController.m
// Couple
//
// Created by Michael Latman on 4/1/13.
// Copyright (c) 2013 Michael Latman. All rights reserved.
//
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
//Rounded corners!
self.view.layer.cornerRadius = 10;
self.view.layer.masksToBounds = YES;
//lol.layer.cornerRadius = 90;
//lol.layer.masksToBounds = YES;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//[logoview setCenter:CGPointMake(100,100)];
[UIView animateWithDuration:4
delay:1
options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
[logoview setCenter:CGPointMake(0, 1)];
}
completion:^(BOOL finished) {
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:3)
嗯,有一个问题是viewDidLoad
太快了。你想要等到至少viewDidAppear
。您的界面尚未在viewDidLoad
中获得实际尺寸。所有发生的事情是你的视图控制器有一个视图;视图尚未在界面中显示,更不用说对用户可见了。
答案 1 :(得分:0)
这样的东西?
[UIView animateWithDuration:4.0 delay:1.0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{
[logoview setCenter:CGPointMake(logoview.center.x, logoview.center.y - 80.0)];
} completion:nil];