gpt4 book ai didi

objective-c - UIView中的UIImage和显示图片部分越界

转载 作者:行者123 更新时间:2023-11-28 18:24:44 25 4
gpt4 key购买 nike

我在 subview 中有一个图像,它比 subview 本身大,是否可以显示 subview 之外的图像部分!已经试过了

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 射线 View 大

在 XrayView 中我有 2 个属性

背景图片前景图片

还有那个方法

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

最佳答案

无论如何, View 都不能在其边界之外绘制。设置clipsToBounds 将只允许 subview 在 View 外渲染,但它不会改变 View 外绘制(在drawRect 方法中)不是这样的事实可能。

如果您有权访问 XRayView 源,请查看图像是如何呈现的。它们可能是在 XRayViewdrawRect 方法中绘制的。您必须添加 UIImageView相反。

关于objective-c - UIView中的UIImage和显示图片部分越界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12497679/

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