Category Archives: iOS/Swift

[iPhone] UIImage 에 마스크 씌우기

UIImage에 마스크를 씌워 특정 영역을 제외하고는 투명처리를 하는 방법입니다. 길게 설명할 필요없이 예제를 보시죠.

[code]CGImageRef imageRef = [[UIImage imageNamed:@”sample.jpg”] CGImage];
CGImageRef maskRef = [[UIImage imageNamed:@”mask.png”] CGImage];
   
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
                                    CGImageGetHeight(maskRef),
                                    CGImageGetBitsPerComponent(maskRef),
                                    CGImageGetBitsPerPixel(maskRef),
                                    CGImageGetBytesPerRow(maskRef),
                                    CGImageGetDataProvider(maskRef),
                                    NULL, false);
   
CGImageRef masked = CGImageCreateWithMask(imageRef, mask);
CGImageRelease(mask);
   
UIImage *maskedImage = [UIImage imageWithCGImage:masked];
CGImageRelease(masked);[/code]

사용자 삽입 이미지결과적으로 위와 같이 마스크를 씌워 마스크 이외의 영역을 투명처리 할 수 있습니다.

여기서 주의할 점은 mask.jpg에는 투명 영역이 존재하면 안됩니다. 투명으로 처리할 영역은 흰색으로 되어있어야 합니다.
참고 :

[iPhone] UIApplication의 delegate 클래스 가져오기

개발한 어플리케이션이 실행되면 제일먼저 main.m 안의 main 함수에서 UIApplicationMain이 호출되고 이어 Info.plistMain nib file base name에 설정된 xib가 로드됩니다. 기본적으로 자동생성되는 MainWindow.xib가 그것입니다.

열어서 File’s Ownerdelegate를 보시면 {프로젝트명}AppDelegate와(이후 TheeyeAppDelegate) 기본적으로 연결되어있는것을 알 수 있습니다.

한마디로 요약하면 UIApplicationMain을 통해 호출되는 MainWindow.xibDelegateTheeyeAppDelegate클래스 라는 것입니다.
사용자 삽입 이미지위의 라이프사이클 그림을 보시면 UIApplicationMain이 호출될 때 applicationDidFinishLaunching이 호출되는 것을 알 수 있습니다.

저것은 TheeyeAppDelegate안에 정의 되어있는 메서드입니다.

이 안에서 각종 View들을 선언하고 Window에 그려내는 초기화 작업을 하게 됩니다.

하지만 다른 클래스에서 이 Delegate 클래스에 접근하고 싶을 경우에는 어떻게 해야 할까요? 다음과 같은 방법이 있습니다.

[code]TheeyeAppDelegate *delegate = [[UIApplication sharedApplication] delegate];[/code]

다음에는 하위 View에서 새로운 View를 생성후에 Window에 붙이고 자기 자신을 소거하는 방법에 대해 적어보겠습니다.

조언 : AccessDenied
참고 : http://discussions.apple.com/message.jspa?messageID=7405287