gpt4 book ai didi

ios - 从左到右将 UIView 移出屏幕并从左再次将其移入

转载 作者:行者123 更新时间:2023-12-01 17:20:32 24 4
gpt4 key购买 nike

如何从左到右将 UIView 移出屏幕,然后从左侧再次将其带入屏幕?!

提前致谢,

最佳答案

您所要做的就是为 View 的 x 原点位置设置动画,并使用设备屏幕来确定多少。所以对于右边的屏幕外:

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_yourView.frame = CGRectMake(screenRect.size.width, _yourView.frame.origin.y, _yourView.frame.size.width, _yourView.frame.size.height);
}
completion:^(BOOL finished) {
//position screen left after animation
_yourView.frame = CGRectMake(-screenRect.size.width, _yourView.frame.origin.y, _yourView.frame.size.width, _yourView.frame.size.height);
}];

在屏幕上返回 0.0 x 位置或任何您的起点:
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_yourView.frame = CGRectMake(0.0, _yourView.frame.origin.y, _yourView.frame.size.width, _yourView.frame.size.height);
}
completion:^(BOOL finished) {
//do something after animation
}];

关于ios - 从左到右将 UIView 移出屏幕并从左再次将其移入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23911468/

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