gpt4 book ai didi

ios - UIImageView 透视倾斜

转载 作者:行者123 更新时间:2023-11-28 20:52:37 24 4
gpt4 key购买 nike

我想要的:https://imgur.com/zE6kgb1

我取得的成就:https://imgur.com/8Ylq5yp

下面是我正在使用的函数:

- (void) showViewWithImageFromAsset: (PHAsset *) asset
{
UIView *imageContainer = [[UIView alloc] initWithFrame:CGRectMake(25, 320, 400, 400)];
[imageContainer setBackgroundColor:[UIColor whiteColor]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 250, 200)];


CGFloat shadowRadius = 0.0;
CGFloat width = imageView.frame.size.width;
CGFloat height = imageView.frame.size.height; // Get width and height of the view

// Plot the path
UIBezierPath *shadowPath = [[UIBezierPath alloc] init];
[shadowPath moveToPoint:CGPointMake(width, 0)];
[shadowPath addLineToPoint:CGPointMake((width)+10, 10)];
[shadowPath addLineToPoint:CGPointMake((width)+10, height-10)];
[shadowPath addLineToPoint:CGPointMake(width, height)];

imageView.layer.shadowColor = UIColor.blackColor.CGColor;
imageView.layer.shadowPath = shadowPath.CGPath;
imageView.layer.shadowRadius = shadowRadius;
imageView.layer.shadowOffset = CGSizeZero;
imageView.layer.shadowOpacity = 1.0;

PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = YES;

PHImageManager *manager = [PHImageManager defaultManager];

// assets contains PHAsset objects.
__block UIImage *ima;

[manager requestImageForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info) {
ima = image;
dispatch_async(dispatch_get_main_queue(), ^{
[imageView setImage:ima];

CATransform3D t = CATransform3DIdentity;
t.m34 = .005;
imageContainer.layer.sublayerTransform = t;
imageView.layer.transform = CATransform3DMakeRotation(-10,0,1,0);
[imageContainer addSubview:imageView];
//[imageContainer addSubview:imageSideView];
[self.view addSubview:imageContainer];
[self.view bringSubviewToFront:imageView];
});

}];

}

如您所见,尽管使用的是倒置(或镜像)图像,但我已经达到了预期的效果。我不打算使用任何第三方框架/库来实现此目的,因为我知道可以通过修改现有代码来实现。

虽然我可以在 CATransform3DMakeRotation(-10,0,1,0) 中更改 y 值,从 1 到 0 以获得正确的图像方向,这也会将透视图更改为此 https://imgur.com/yKL4NQA

我需要一些东西来在不改变视角的情况下获得正确的图像。任何帮助是极大的赞赏。

最佳答案

最大的问题是 CATransform3DMakeRotation 的第一个参数需要是弧度,而不是度数。

imageView.layer.transform = CATransform3DMakeRotation(-10 * M_PI / 180.0, 0, 1, 0);

然后你需要改变shadowPath的x:

[shadowPath moveToPoint:CGPointMake(0, 0)];
[shadowPath addLineToPoint:CGPointMake(-10, 10)];
[shadowPath addLineToPoint:CGPointMake(-10, height-10)];
[shadowPath addLineToPoint:CGPointMake(0, height)];

这给出了预期的结果。

关于ios - UIImageView 透视倾斜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56402980/

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