iphone - 左右滑动 UIView

标签 iphone objective-c ios cocoa-touch uiview

我正在尝试为 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/

相关文章:

iphone - 可编辑表格单元格的良好教程/示例代码?

objective-c - 带有 NSDictionary 的 EXC_BAD_ACCESS

ios - 什么是 CGFloat.random(min : CGFloat, max : CGFloat) of swift 2 in swift 3?

objective-c - 两个数组的对称差异

java - 使用库或算法压缩视频大小的最快方法

ios - 调试区只有 (lldb) 输出,没有其他信息

ios - 将图像转换为 NSData 以保存在核心数据中

ios - Swift - 如何在按下不同 UITableView 单元格中的另一个播放按钮时自动停止当前播放的音频?

iphone - 使用蒙皮控件创建 iPhone 屏幕

ios - iOS 应用程序是否将 NSUserdefaults 信息保存在同一个地方?