Ios UIButton滑入,而不是淡入
我在Ios UIButton滑入,而不是淡入,ios,uibutton,uiviewanimation,Ios,Uibutton,Uiviewanimation,我在UIViewController中有一个ui按钮,当应用程序打开时,我当前可以“淡入”查看该按钮我想让ui按钮从左向右滑动。 我不知道如何让它从左向右滑动,我的尝试失败了,尽管我已经把“淡入”的东西固定下来了 你能帮我什么忙吗?谢谢我可以根据需要添加更多的代码- ViewController.h @property (weak, nonatomic) IBOutlet UIButton *buttonOne; ViewController.m - (void)viewDidLoad {
UIViewController
中有一个ui按钮
,当应用程序打开时,我当前可以“淡入”查看该按钮我想让ui按钮
从左向右滑动。
我不知道如何让它从左向右滑动,我的尝试失败了,尽管我已经把“淡入”的东西固定下来了
你能帮我什么忙吗?谢谢我可以根据需要添加更多的代码-
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动画块:
// 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!");
}
];
有一个方法,您可以查看以了解更多信息。您需要设置按钮帧的动画,而不是使用动画曲线 从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!");
}
];
有一个网站,您可以查看以了解更多信息。非常感谢您的回复!滑动它很有效,但快速提问,我的按钮2是W280xH60,并且居中,那么我如何让它移动到ViewController的该区域,而不是现在它停留在屏幕的右半部分?只需更改
newFrm.origin.x=20代码>?只需计算x在屏幕上居中的位置。所以你的buttonX=(viewWidth/2)-(buttonWidth/2)真是太棒了,它刚刚开始工作!最后一个问题,我想从左到右,而不是从右到左,哪个值会被更改?只需将第一个CGRect更新为,而不是-yourButton.frame.size.width它只是视图的大小,所以它将是CGRectGetWidth(self.view.frame)而不是-yourButton.frame.size…非常感谢您的回复!滑动它很有效,但快速提问,我的按钮2是W280xH60,并且居中,那么我如何让它移动到ViewController的该区域,而不是现在它停留在屏幕的右半部分?只需更改newFrm.origin.x=20代码>?只需计算x在屏幕上居中的位置。所以你的buttonX=(viewWidth/2)-(buttonWidth/2)真是太棒了,它刚刚开始工作!最后一个问题,我想从左到右,而不是从右到左,哪个值会被更改?只需将第一个CGRect更新为,而不是-yourButton.frame.size.width它只是视图的大小,所以它将是CGRectGetWidth(self.view.frame)而不是-yourButton.frame.size…谢谢您回复我!滑动它很有效,但也有一个快速的问题,我的按钮2是W280xH60并且居中,那么我如何让它移动到ViewController的那个区域,而不是现在它移动到中间并挂在屏幕的左侧?只是将setFrame:CGRrectMake(0
更改为setFrame:CGRrectMake(20
并使其工作!最后一个问题,我希望动画从左向右移动,但它当前从右向左移动,我会为此更改哪个值?更改CGRectMake的X坐标(第一个值)。在将动画设置为类似于-CGRectGetWidth(buttonTwo.frame)的内容之前,应该更改rect
,这意味着按钮将从框架右侧开始,其整个宽度超出框架。如果要将按钮居中,请使用buttonTwo.center=viewController.view.center
如果我使用-CGRectGetWidth(buttontw.frame)
,按钮从右到左。我需要它从左到右,所以我不确定如何设置-CGRectGetWidth
?很抱歉,我解释得不太清楚。谢谢你回复我!滑动它很有效,但也有一个快速的问题,我的按钮是W280xH60,并且居中,所以我如何让它移动到那个位置ViewController的t区域,而不是现在,它移过中心并挂在屏幕的左侧?只是将setFrame:CGRrectMake(0
更改为setFrame:CGRrectMake(20
并使其工作!最后一个问题,我希望动画从左向右移动,但它当前从右向左移动,我会为此更改哪个值?更改CGRectMake的X坐标(第一个值)。在将动画设置为类似于-CGRectGetWidth(buttonTwo.frame)的内容之前,应该更改rect
,这意味着按钮将从框架右侧开始,其整个宽度超出框架。如果要将按钮居中,请使用buttonTwo.center=viewController.view.center
如果我使用-CGRectGetWidth(buttontw.frame)
,按钮从右到左。我需要它从左到右,所以我不确定如何设置-CGRectGetWidth
?抱歉,我解释得不太清楚。