2010-12-03 4 views
1

3.2 이상의 iPad 앱을 만들고 있습니다. 내 애플 리케이션은 그 아래 모든 것을 더 어둡게 만드는 반투명 (semi-transparency) 오버레이 뷰를 가지고있다. 이 뷰의 중간에이 코드로, 상처를 통해 배경 필터의 일부를 수 있도록이 반투명에 구멍을 자르고 있어요 :부모보기에서 둥근 모서리가있는 UIView를 제거하려면 어떻게해야합니까?

- (void)drawRect:(CGRect)rect { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGRect intersection = CGRectIntersection(hole.frame, rect); 
    CGContextClearRect(context, intersection); 
} 

또한, '구멍'보기를 둥글게 한 모서리를 통해 적용 이 하나의 작은 문제를 제외하고 잘 작동

self.layer.cornerRadius = 4.25; 

-이 둥근 모서리을 고려, 그래서 밖으로 다진 도착 구멍 대신에 둥근의 사각 모서리를 가지고 있지 않습니다. 이 문제를 해결할 필요가 있지만 어떻게 될지 모르겠습니다. 어떤 아이디어, 예, 생각? 만약 cornerRadius 층의 속성을 변경하는 경우 콘텐츠가 라운딩에 잘릴 수 있도록

답변

3

가 여기에 내가이 일을 받고 결국 방법입니다. 이렇게하면 'hole'UIView와 같은 프레임에 구멍이 생겨서 자체 (UIView)에서자를 수 있습니다. 이렇게하면 방해받지 않고 '구멍'뒤에있는 것이 무엇이든 볼 수 있습니다.

- (void)drawRect:(CGRect)rect { 
    CGFloat radius = self.hole.layer.cornerRadius; 
    CGRect c = self.hole.frame; 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

     // this simply draws a path the same shape as the 'hole' view 
    CGContextMoveToPoint(context, c.origin.x, c.origin.y + radius); 
    CGContextAddLineToPoint(context, c.origin.x, c.origin.y + c.size.height - radius); 
    CGContextAddArc(context, c.origin.x + radius, c.origin.y + c.size.height - radius, radius, M_PI_4, M_PI_2, 1); 
    CGContextAddLineToPoint(context, c.origin.x + c.size.width - radius, c.origin.y + c.size.height); 
    CGContextAddArc(context, c.origin.x + c.size.width - radius, c.origin.y + c.size.height - radius, radius, M_PI_2, 0.0f, 1); 
    CGContextAddLineToPoint(context, c.origin.x + c.size.width, c.origin.y + radius); 
    CGContextAddArc(context, c.origin.x + c.size.width - radius, c.origin.y + radius, radius, 0.0f, -M_PI_2, 1); 
    CGContextAddLineToPoint(context, c.origin.x + radius, c.origin.y); 
    CGContextAddArc(context, c.origin.x + radius, c.origin.y + radius, radius, -M_PI_2, M_PI, 1); 

     // finish 
    CGContextClosePath(context); 
    CGContextClip(context); // this is the secret sauce 
    CGContextClearRect(context, c); 
} 
0

, 또한 위해 연관된보기 YESclipsToBounds에 설정한다.

+0

clipsToBounds는 수신자보기 범위 밖에서 개체를 그릴 수 있는지 여부입니다. 즉, 부모 UIView 바운드 바깥에 UIView의 하위 뷰를 그릴 수 있습니다. 그게 어떻게 도움이 될지 모르겠다. .. – Allyn

+0

'cornerRadius'는 (대략적인 관점에서) 클리핑 경로에 통합되므로 내용에 영향을 미치기 위해서는 클리핑이 활성화되어 있어야한다. –

+0

방금 ​​시도했지만 모서리를 수정하지 않은 것 같습니다. 작동시키기 위해해야 ​​할 일이 있습니까? – Allyn

1

마스킹이라고하는 작업을 마스킹이라고합니다. 코어 그래픽을 사용하여 현재 그래픽 컨텍스트를 마스크 할 수 있습니다. 여기에 주제에 대한 애플의 설명서를 참조하십시오 :

http://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html#//apple_ref/doc/uid/TP30001066-CH212-CJBHDDBE

+0

이미지를 참조하는 모습 -보기를 가려야합니다. 작업을 수행하기 위해 뷰를 이미지로 렌더링하는 것이 적절합니까? – Allyn

+0

확실히. 여기에 게시 한 코드를 수정할 수 있습니다. http://stackoverflow.com/questions/4168484/exporting-customized-uitableviewcells-into-uiimage/4169320#4169320 – Ryan

관련 문제