I have an image in a subview that is bigger than the subview it self, is it possible to display parts of the image that are out of the subview! have tried the
view.clipsToBounds=NO;
but no lack still.
here is part of my code so far.
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"]]];
the foreground and the background images are bigger than the xray view
in XrayView i have 2 properties
backgroundImage
foregroundImage
and that method
- (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());
}
A view can’t draw outside of its bounds no matter what. Setting
clipsToBoundswill only allow subviews to be rendered outside of the view, but it doesn’t change the fact that drawing (in thedrawRectmethod) outside of the view is not possible.If you have access to the
XRayViewsources, see how the images are rendered. They’re probably drawn in thedrawRectmethod ofXRayView. You have to add aUIImageViewinstead.