gpt4 book ai didi

ios - UIButton 滑入,而不是淡入

转载 作者:行者123 更新时间:2023-11-28 20:16:39 24 4
gpt4 key购买 nike

我在 UIViewController 中有一个 UIButton,我目前在应用程序打开时“淡入”以查看它。 不过,我想让 UIButton 从左向右滑入。

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

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

ViewController.h

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

ViewController.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];
}

最佳答案

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

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

// 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!");
}
];

有一个 good tutorial over at Ray Wenderlich您可以查看以了解更多信息。

关于ios - UIButton 滑入,而不是淡入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17823266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com