sud*_*-rf 13 iphone directory cocoa-touch transform objective-c
我想知道是否有一种方法可以将我的视图转换为类似iPhone文件夹的方式.换句话说,我希望我的视图在中间的某处分开,并在其下方显示一个视图.这可能吗?
编辑: 根据下面的建议,我可以通过这样做截取我的应用程序:
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
但是,不知道该怎么做.
编辑:2 我已经想出如何在我的视图中添加一些阴影,这是我已经实现的(裁剪以显示相关部分):
编辑:3
小智 6
基本的想法是拍摄你当前的状态并将其分割到某个地方.然后通过设置新框架为两个部分设置动画.我不知道如何以编程方式截取屏幕截图,因此我无法提供示例代码...
编辑:嘿嘿它看起来不是很好但是它有效^^
// 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);
}];
Run Code Online (Sandbox Code Playgroud)
您可以取消注释这两.contentMode
行,质量会提高,但在我的情况下,子视图的偏移量为10px左右(您可以通过为两个子视图设置背景颜色来查看)
//编辑2:确定发现了这个bug.已经使用了整个320x480屏幕,但不得不切断状态栏,所以它应该是320x460,一切都很好;)
归档时间: |
|
查看次数: |
3547 次 |
最近记录: |