0

我有一个UIButtonUIViewController应用程序打开时可以“淡入”查看的内容。 不过,我想让它UIButton从左到右滑入。

我不知道如何让它从左到右滑入,我的尝试失败了,即使我已经把“淡入”的东西固定下来了。

你能给我什么帮助吗?谢谢!我可以根据需要添加更多代码-

视图控制器.h

@property (weak, nonatomic) IBOutlet UIButton *buttonOne;

视图控制器.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
        NSTimer *timermovebutton = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(movebutton) userInfo:nil repeats:NO];
    [timermovebutton fire];
}

-(void) movebuttontwo
{
    buttonTwo.alpha = 0;
    [UIView beginAnimations:Nil context:Nil];
    [UIView setAnimationDelay:0.5];
    [UIView setAnimationCurve:UIViewAnimationTransitionCurlUp];

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:1.0];
    buttonTwo.alpha = 1.0;

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];
}
4

2 回答 2

2

您需要为按钮框架设置动画,而不是使用动画曲线。

从 iOS 4 开始,我们有了 UIView 动画块:

// first set the UIButton frame to be outside of your view:
// we are only concerned about it's location on the X-axis so let's keep all properties the same
[buttonTwo setFrame:CGRectMake(CGRectGetMaxX(self.view.frame), CGRectGetMinY(buttonTwo.frame), CGRectGetWidth(buttonTwo.frame), CGRectGetHeight(buttonTwo.frame))];
[UIView animateWithDuration:0.5
                      delay:0
                    options:UIViewAnimationCurveEaseOut
                 animations:^{
                     // set the new frame
                     [buttonTwo setFrame:CGRectMake(0, CGRectGetMinY(buttonTwo.frame), CGRectGetWidth(buttonTwo.frame), CGRectGetHeight(buttonTwo.frame))];
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }
];

Ray Wenderlich有一个很好的教程,您可以查看以了解更多信息。

于 2013-07-24T00:47:27.033 回答
1
//Set your button off the screen to the left
yourButton.frame = CGRectMake(-yourButton.frame.size.width, yourButton.frame.origin.y, CGRectGetWidth(yourButton.frame), CGRectGetHeight(yourButton.frame));

//Create the ending frame or where you want it to end up on screen
CGRect newFrm = yourButton.frame;
newFrm.origin.x = 100;

//Animate it in
[UIView animateWithDuration:2.0f animations:^{
    yourButton.frame = newFrm;
}];
于 2013-07-24T00:46:27.853 回答