gpt4 book ai didi

iphone - 如何制作类似 iPhone 文件夹的东西?

转载 作者:太空狗 更新时间:2023-10-30 03:20:41 24 4
gpt4 key购买 nike

我想知道是否有一种方法可以将 View 转换为类似于 iPhone 文件夹的 View 。换句话说,我希望我的 View 在中间某处 split 并显示其下方的 View 。这可能吗?

alt text

编辑:根据下面的建议,我可以通过执行以下操作截取我的应用程序的屏幕截图:

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是,不确定如何处理。

编辑:2我已经想出如何在我的 View 中添加一些阴影,这是我所取得的成就(裁剪以显示相关部分):

alt text

编辑:3

http://github.com/jwilling/JWFolders

最佳答案

基本的想法是拍一张你当前状态的照片,然后把它分割到某个地方。然后通过设置一个新帧来为这两个部分设置动画。我不知道如何以编程方式截取屏幕截图,所以我无法提供示例代码......

编辑:嘿嘿它看起来不太好但它有效^^

// wouldn't be sharp on retina displays, instead use "withOptions" and set scale to 0.0
// UIGraphicsBeginImageContext(self.view.bounds.size);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *f = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGRect fstRect = CGRectMake(0, 0, 320, 200);
CGRect sndRect = CGRectMake(0, 200, 320, 260); // was 0,200,320,280


CGImageRef fImageRef = CGImageCreateWithImageInRect([f CGImage], fstRect);
UIImage *fCroppedImage = [UIImage imageWithCGImage:fImageRef];
CGImageRelease(fImageRef);

CGImageRef sImageRef = CGImageCreateWithImageInRect([f CGImage], sndRect);
UIImage *sCroppedImage = [UIImage imageWithCGImage:sImageRef];
CGImageRelease(sImageRef);


UIImageView *first = [[UIImageView alloc]initWithFrame:fstRect];
first.image = fCroppedImage;
//first.contentMode = UIViewContentModeTop;
UIImageView *second = [[UIImageView alloc]initWithFrame:sndRect];
second.image = sCroppedImage;
//second.contentMode = UIViewContentModeBottom;

UIView *blank = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
blank.backgroundColor = [UIColor darkGrayColor];

[self.view addSubview:blank];
[self.view addSubview:first];
[self.view addSubview:second];

[UIView animateWithDuration:2.0 animations:^{
second.center = CGPointMake(second.center.x, second.center.y+75);
}];

您可以取消注释两条 .contentMode 行,质量会提高,但在我的例子中, subview 有 10px 左右的偏移量(您可以通过为两个 subview 设置背景颜色来查看)

//编辑 2:确定发现了那个错误。使用了整个 320x480 屏幕,但不得不切断状态栏,所以它应该是 320x460 并且一切正常;)

关于iphone - 如何制作类似 iPhone 文件夹的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4493837/

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