Objective c UIView中的UIImage和显示图像部分超出范围
我在子视图中有一个图像,它比它本身的子视图大,是否可以显示子视图之外的部分图像!我试过了Objective c UIView中的UIImage和显示图像部分超出范围,objective-c,ios,uiview,uiimage,Objective C,Ios,Uiview,Uiimage,我在子视图中有一个图像,它比它本身的子视图大,是否可以显示子视图之外的部分图像!我试过了 view.clipsToBounds=NO; 但仍然不乏 这是我到目前为止的部分代码 xRayView = [[XRayView alloc] initWithFrame: CGRectMake((1024 - 800) / 2, self.device.frame.origin.y - 26, 800,530)]; xRayView.clipsToBounds=NO;
view.clipsToBounds=NO;
但仍然不乏
这是我到目前为止的部分代码
xRayView = [[XRayView alloc] initWithFrame: CGRectMake((1024 - 800) / 2, self.device.frame.origin.y - 26, 800,530)];
xRayView.clipsToBounds=NO;
[xRayView setForgroundImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"xray_foreground_01" ofType: @"png"]]];
[xRayView setBackgroundImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"xray_background_01" ofType: @"png"]]];
前景和背景图像比X射线视图大
在x光视图中,我有两个属性
背景图像
前景图像
那方法呢
- (void)drawRect: (CGRect)rect
{
[super drawRect: rect];
CGRect forgroundClips[] = {
CGRectMake((self.frame.size.width - self.forgroundImage.size.width)/2, 0, self.forgroundImage.size.width, currentPan.origin.y),
CGRectMake((self.frame.size.width - self.forgroundImage.size.width)/2, currentPan.origin.y + currentPan.size.height, self.forgroundImage.size.width, self.forgroundImage.size.height - (currentPan.origin.y + currentPan.size.height))
};
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, self.bounds.size.height);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1, -1);
CGContextClipToRects(UIGraphicsGetCurrentContext(), forgroundClips, sizeof(forgroundClips) / sizeof(forgroundClips[0]));
//CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height), self.forgroundImage.CGImage);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake((self.frame.size.width - self.forgroundImage.size.width)/2, 0, self.forgroundImage.size.width, self.forgroundImage.size.height), self.forgroundImage.CGImage);
CGContextRestoreGState(UIGraphicsGetCurrentContext());
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, self.bounds.size.height);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1, -1);
CGContextClipToRect(UIGraphicsGetCurrentContext(), currentPan);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 153, 153, 153, 0.5);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 3);
CGContextStrokeRect(UIGraphicsGetCurrentContext(), currentPan);
//CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height), self.backgroundImage.CGImage);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake((self.frame.size.width - self.backgroundImage.size.width)/2 , 0, self.backgroundImage.size.width, self.backgroundImage.size.height), self.backgroundImage.CGImage);
CGContextRestoreGState(UIGraphicsGetCurrentContext());
// Draw a yellow hollow rectangle
// CGContextRestoreGState(UIGraphicsGetCurrentContext());
}
clipstobunds
表示图像将被剪裁到边界之外。确保将其设置为NO
。(这是在原始帖子中说的clipstobunds=YES;
)时发布的)clipstobunds
意味着图像将被剪切到边界之外。确保将其设置为NO
。(这是在最初的帖子中说的clipsToBounds=YES;
)时发布的)视图无论如何都不能超出其边界。设置clipstobunds
将只允许在视图外部渲染子视图,但不会改变无法在视图外部绘制(在drawRect
方法中)的事实
如果您有权访问
XRayView
源,请查看图像的渲染方式。它们可能是在XRayView
的drawRect
方法中绘制的。您必须添加一个视图。视图无论如何都不能超出其边界。设置clipstobunds
将只允许在视图外部渲染子视图,但不会改变无法在视图外部绘制(在drawRect
方法中)的事实
如果您有权访问
XRayView
源,请查看图像的渲染方式。它们可能是在XRayView
的drawRect
方法中绘制的。您必须添加一个。是的,对不起,我的错,它设置为“否”,但仍然存在问题!我想这可能是因为您正在使用这些背景图像,进入X光视图,确保backgroundImage(视图)和ForeggroundImage(视图)设置为clipsToBounds=NO
是的,对不起,我的错,设置为NO,但仍然存在问题!我认为这可能是因为您正在使用这些背景图像,请进入x光视图,并确保backgroundImage(view)和ForeggroundImage(view)设置为clipsToBounds=NO
尝试为保存UIImageView
的UIImageView
对象设置CliptBounds
属性和背景图像
。如果这还不行,您可能需要向我们提供有关XRayView
的视图继承权的更多详细信息。请尝试为保存您的forgroundImage
[SIC]和backgroundImage
的UIImageView
对象设置cliptobunds
属性。如果这还不行,您可能需要向我们提供有关XRayView
的视图继承权的更多详细信息。