gpt4 book ai didi

iphone - 左右滑动 UIView

转载 作者:行者123 更新时间:2023-11-29 13:41:22 25 4
gpt4 key购买 nike

我正在尝试为 UIView 设置动画以左右滑动。我尝试的是截取当前 View 的屏幕截图,而不是在更新屏幕外 View 的内容时用屏幕截图替换 View ,然后制作动画。但是屏幕截图没有显示在屏幕上。它只是黑色,直到原始 View 滑回屏幕上。这是我正在使用的代码:

    UIGraphicsBeginImageContext(self.view.window.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
iv.image = image;
[self.view.window insertSubview:iv aboveSubview:self.view];
self.view.frame = CGRectMake(-self.view.frame.size.width, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionCurveEaseInOut animations:^{
iv.frame = CGRectMake(self.view.frame.size.width*2, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self loadData];
self.view.frame = CGRectMake(0, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:NULL];
[iv removeFromSuperview];
[iv release];

最佳答案

我发现了问题。我只需要在完成 block 中执行 [iv removeFromSuperview]; 。现在可以使用了。

关于iphone - 左右滑动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9055465/

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