Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIImageView透视倾斜_Ios_Objective C_Uiimageview - Fatal编程技术网

Ios UIImageView透视倾斜

Ios UIImageView透视倾斜,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,我想要什么: 我所取得的成就: 以下是我正在使用的函数: - (void) showViewWithImageFromAsset: (PHAsset *) asset { UIView *imageContainer = [[UIView alloc] initWithFrame:CGRectMake(25, 320, 400, 400)]; [imageContainer setBackgroundColor:[UIColor whiteColor]]; UII

我想要什么

我所取得的成就

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

- (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];
                    });

                }];

}
正如你所看到的,我已经达到了预期的效果,尽管我使用了一个反转(或镜像)的图像。我不打算使用任何第三方框架/库来实现这一点,因为我知道修改现有代码是可能的

虽然我可以将CATTransferM3dMakeRotation(-10,0,1,0)中的y值从1更改为0以获得正确的图像方向,但这也会将透视图更改为此


我需要一些东西在不改变视角的情况下获得正确的图像。非常感谢您的帮助

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

imageView.layer.transform = CATransform3DMakeRotation(-10 * M_PI / 180.0, 0, 1, 0);
然后您需要更改阴影路径的
x

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

这将给出所需的结果。

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

imageView.layer.transform = CATransform3DMakeRotation(-10 * M_PI / 180.0, 0, 1, 0);
然后您需要更改阴影路径的
x

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

这会得到理想的结果。

谢谢你,效果不错。弧度部分是我缺少的一点。再次感谢。谢谢你,这很有效。弧度部分是我缺少的一点。再次感谢。