Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.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
Objective c 完成绘图后调整UIImageView的大小_Objective C_Ios_Xcode_Uiview_Uiimageview - Fatal编程技术网

Objective c 完成绘图后调整UIImageView的大小

Objective c 完成绘图后调整UIImageView的大小,objective-c,ios,xcode,uiview,uiimageview,Objective C,Ios,Xcode,Uiview,Uiimageview,我试图在我的应用程序中划清界限。首先,我将图形窗口大小设置为视图大小。完成绘制后,我想调整UIImageView的大小,以便图形周围没有空白。是否有一个选项可以像UILabel中的sizeToFit那样自动调整UIImageView的大小 UIGraphicsBeginImageContext(self.vwDesktop.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, self.vwDesktop.frame.s

我试图在我的应用程序中划清界限。首先,我将图形窗口大小设置为视图大小。完成绘制后,我想调整UIImageView的大小,以便图形周围没有空白。是否有一个选项可以像UILabel中的sizeToFit那样自动调整UIImageView的大小

   UIGraphicsBeginImageContext(self.vwDesktop.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.vwDesktop.frame.size.width, self.vwDesktop.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    CGContextFlush(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    drawImage.userInteractionEnabled = YES;

如果我正确理解了您的问题,您需要的是
UIView
上的
contentMode
属性(因此
UIImageView
)?这将决定图像的大小以适合视图

另外,您不需要在每个核心图形函数中调用
UIGraphicsGetCurrentContext()
。为什么不将上下文保存在局部变量中:

CGContextRef ctx = UIGraphicsGetCurrentContext();
每次需要引用当前上下文时都使用该
CGContextRef


然而,在我看来,您可以在
UIView
drawRect
方法中完成所有这些,而不必创建图像上下文,除非出于某种原因,您希望保留正在绘制的行的
UIImage

好的。我将在局部变量中保存上下文。我要做的是允许用户在屏幕上绘制一些东西,然后我将插入一个数组。我的数组由许多图像(照片、用户绘制、戳记)组成。因此,当前图形的UIImageView由一些透明边框组成,我不希望它,因为它会影响我选择要编辑的视图。