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

标签 ios animation uiview

如何从左到右将 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/

相关文章:

ios - 如何使用 pdfkit 从相机拍摄的图像创建 pdf

python - 如何为包含动画元素的项目设置 QtDesigner?

ios - 如何在平移手势事件期间转换一条线?

ios - 来自 Web 控制台的 Parse.com 通知

ios - AppDelegate 的 'downcasting' 会失败吗?

Python Matplotlib : Centering figure around a moving artist

ios - AutoLayout 和 AVCaptureVideoPreviewLayer

ios - 将参数从 Storyboard传递到自定义 UIView iOS

ios - 如何检测 NSUserDefault 的变化?

CSS3 背景(URL 图像)在其他动画运行时设置动画