Dev/iOS2011. 9. 27. 16:07

CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(40));

[ImageView setTransform:landscapeTransform];


Posted by 놀란
Dev/iOS2011. 9. 27. 16:04


- (UIImage *)convertImageToGrayScale:(UIImage *)image { 

// Create image rectangle with current image width/height 

CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);

// Grayscale color space 

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

// Create bitmap content with current image size and grayscale colorspace 

CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);

// Draw image into current context, with specified rectangle 

// using previously defined context (with grayscale colorspace) 

CGContextDrawImage(context, imageRect, [image CGImage]);

// Create bitmap image info from pixel data in current context 

CGImageRef imageRef = CGBitmapContextCreateImage(context);

// Create a new UIImage object  

UIImage *newImage = [UIImage imageWithCGImage:imageRef];

// Release colorspace, context and bitmap information 

CGColorSpaceRelease(colorSpace);

CGContextRelease(context);

CFRelease(imageRef);

// Return the new grayscale image 

return newImage;

}

파라미터를 추가하면 scale도 변경 가능하네요.


Posted by 놀란
Dev/iOS2011. 9. 23. 16:41


UIImage *origianlImage = [UIImage imageNamed:@"source.png"];

UIImage *flippedImage = [UIImage imageWithCGImage:originalImage.CGImage

scale:1.0 

orientaion:UIImageOrientationLeftMirrored];

orientaion 종류

typedef enum {

    UIImageOrientationUp,            // default orientation

    UIImageOrientationDown,          // 180 deg rotation

    UIImageOrientationLeft,          // 90 deg CCW

    UIImageOrientationRight,         // 90 deg CW

    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip

    

    UIImageOrientationDownMirrored,  // horizontal flip

    UIImageOrientationLeftMirrored,  // vertical flip

    UIImageOrientationRightMirrored, // vertical flip

} UIImageOrientation;

Posted by 놀란
Dev/iOS2011. 8. 30. 12:02

특정 instance 의 클래스 여부를 확인한다.

- (BOOL)isKindOfClass:(Class)aClass

retrun 값은 BOOL (1, 0) - 해당 클래스에 속하면 YES(1), 아니면 NO(0)

사용법:

id result  일 경우,

[result isKindOfClass:[NSArray class]];


- result가 NSArray 인지 확인!

Posted by 놀란
Dev/iOS-cocos2d2011. 8. 5. 12:03

좌표(터치)를 이용하여 특정 스프라이트 터치 체크하는 방법

체크는 CGRectContainsPoint 메소드 사용. 참고:( http://goo.gl/BQ2HQ )

CGRectContainsPoint 에 필요한 인자값은 Rect 와 Point

Rect(사각형 스프라이트) 안에 Point 가 있는지 체크하는 메소드 입니다.

사각형 범위를 가져오기 위해서는 해당 sprite의 position과 width, height 를 이용하여 범위를 가져와야 합니다.

cocos2d 에서는 이것을 boundingBox 메소드를 이용하여 쉽게 가져올 수 있습니다.

CGPoint touchPoint = [touch locationInView:[touch view]];

touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];

CCSprite *sprite = [CCSprite spriteWitheFile:@"파일명"];

if (CGRectContainsPoint([sprite boundingBox], touchPoint)) {

    NSLog(@"해당 스프라이트 터치 성공.");

} else {

    NSLog(@"해당 스프라이트 터치 안됨.");

}


진작에 쓸걸... 그동안 position, width, height 계산한걸 생각하면.... -_-;;



Posted by 놀란
Dev/iOS2011. 8. 3. 21:05

  • XCode4 에서는 XCode3 에서 처럼 ip 주소로 등록이 안됨.
  • 도메인 주소가 필요함.
  • /private/etc/hosts 파일 수정 (저 같은 경우 (자신의 i.p address)     hosturl 으로 추가)
  • XCode4 repository 주소에 http://hosturl/myproject 입력.
  • 아이디/패스워드 입력
  • 참고 URL : http://stackoverflow.com/questions/6748387/xcode4-add-repository-host-unreachable
  • 이와 다른 경우로는 터미널에서 svn list 명령어를 이용하여 로그인 인증을 하면 되는 경우도 있다고 함.
    • svn list http://(i.p address)/myproject

Posted by 놀란
Dev/iOS2011. 8. 2. 14:38

일반적으로 바탕화면에 숫자 표시 하는 것을 뱃지 표시라 한다.

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: value(숫자) ];

Posted by 놀란
Dev/iOS2011. 8. 2. 11:00

새로 나온 OSX Lion 을 설치했습니다.

새로운 기분으로 XCode4 로 설치하기로 마음 먹었습니다. (Lion 에는 Xcode 3 설치가 안된다고도 합니다.)

Lion 에서는 app store 를 통해 Xcode4 를 무료로 설치할 수 있습니다.

Lion의 바뀐 메뉴 Launchpad 를 통해서 Xcode4 installer 를 실행 시키면 설치가 시작됩니다.

그러나, 설치 도중에 iTunes 가 실행 중이라며 닫아주라는 메시지를 받을 수 있습니다.

분명히 iTunes 는 닫혀있는데 왜 뜨는지 알 수 없습니다. 알럿 창은 닫히지도 않습니다.

이럴 때, 윈도우의 작업관리자와 같은 '활성상태보기' 를 실행시켜서 확인해보면 됩니다.

'활성상태보기'는 Lanchpad -> 유틸리티 -> 활성상태보기 에 위치하고 있습니다.

활성상태보기 오른쪽 상단의 검색 창에 'itunes' 를 입력하면 iTunes helper 가 실행중 상태로 뜨는 걸 확인할 수 있습니다.

이것을 강제종료(프로세스 종료) 해주면 끝!

바로 설치가 진행됩니다.


여기까지 입니다.

Posted by 놀란
Dev/iOS2011. 7. 20. 12:43

/* Points. */


struct CGPoint {

  CGFloat x;

  CGFloat y;

};

typedef struct CGPoint CGPoint;


/* Sizes. */


struct CGSize {

  CGFloat width;

  CGFloat height;

};

typedef struct CGSize CGSize;


/* Rectangles. */


struct CGRect {

  CGPoint origin;

  CGSize size;

};

typedef struct CGRect CGRect;



Posted by 놀란
Dev/iOS-cocos2d2011. 7. 12. 14:12

- (CGPoint)convertToNodeSpace:(CGPoint)worldPoint

worldPoint(전체 화면상의 좌표) 값을 특정노드(스프라이트, 레이어 포함) 기준의 좌표값으로 변경


- (CGPoint)convertToWorldSpace:(CGPoint)nodePoint

특정노드(스프라이트, 레이어 포함)에서의 좌표값을 worldPoint(전체 화면상의 좌표) 기준의 좌표값으로 변경


Posted by 놀란
Dev/iOS2011. 7. 11. 15:01

기본 번들 디렉토리 가져오기

NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

디렉토리내 파일리스트 가져오기

NSArray *arrContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:nil];

for (NSString *strFileName in arrContents) {

NSLog(@"filename--> %@", strFileName);

}


Posted by 놀란
Dev/iOS-cocos2d2011. 7. 11. 11:00

배경 등과 같은 스프라이트 이미지 2개를 나란히 붙였을 때,

가는 실선이 나타나는 것을 볼 수 있는데, 이렇게 두 이미지가 만나는 부분에 검은색 실선이 보이는 이유는 기본적으로 안티앨리어싱( anti-aliasing)이 켜져있기 때문이다.

검은색 실선을 보이지 않게 하려면 아래 코드를 이용하여 안티앨리어싱 기능을 끄면 된다.

[targetSprite1.texture setAliasTexParameters];

[targetSprite2.texture setAliasTexParameters];



Posted by 놀란
Dev/iOS2011. 6. 27. 11:36

한 클래스로부터 상속한 메서드를 오버라이드하는 대신 그 메서드를 확장하는 것도 가능하다. 메서드를 확장하기 위해서는 새로운 구현 파일에서 메서드를 오버라이드하면서 상위 클래스의 같은 메서드를 호출하면 된다.

즉, 오버라이드할 메서드의 첫 부분에서 [super 메서드이름]; 과 같이 넣어줌으로써 메서드 오버라이드가 진행되기 전에 상위 메서드의 원 기능을 동작시켜 주는 것이다.


첫 부분인지 제일 마지막 부분에 쓰는 것 중에 어떤게 맞는건가 했는데... 첫 부분이였구나...


출처: 아이폰 프로그래밍 가이드 (프리렉)

Posted by 놀란
Dev/iOS2011. 6. 20. 15:08

  • 누르기(Tap) - 컨트롤 혹은 아이템을 누르거나 선택
  • 끌기(Drag)   - 스크롤 혹은 이동
  • 튕기기(Flick) - 빠른 스크롤 혹은 빠른 이동
  • 쓸기(Swipe)   - 테이블 뷰에서 삭제 버튼을 드러냄
  • 두번 누르기(Double Tap) - 확대한 후 컨텐츠나 이미지의 중앙을 맞춤. 이미 확대되어 있으면 축소
  • 벌리기(Pinch open) - 확대
  • 오므라기(Pinch close) - 축소
  • 터치한 후 유지(Touch and hold) - 편집 가능한 텍스트에서 커서가 가리키는 곳에 돋보기를 보여줌



Posted by 놀란
Dev/iOS-cocos2d2011. 6. 16. 11:27

1. cocos2d 설치와 샘플 프로젝트



Posted by 놀란
Dev/iOS-cocos2d2011. 6. 15. 12:17


MAX(A, B) - A, B 값 중 최대값 리턴

MIN(A, B) - A, B 값 중 최소값 리턴

ABS(A) - A 값의 절대값


Posted by 놀란
Dev/iOS2011. 6. 2. 22:17

문자열을 식별자를 이용하여 배열로 나누기

componentsSeparatedByString 메소드

NSString *string = @"one:two:three:four";

NSArray *chunks = [string componetsSeparatedByString: @":"];


반대로 배열의 객체를 합쳐 하나의 문자열로 만들기

componentsJoinedByString 메소드 사용

string = [chunks componentsJoinedByString: @"-"];

결과 @"one-two-three-four"



출처 : Objective-C 2.0 (이종웅 저)

Posted by 놀란
Dev/iOS2011. 6. 2. 21:56

arrayWithObject : 클래스 메소드를 사용해서 새 NSArray 를 만들 수 있다. 배열의 목록을 콤마로 구분해서 인수를 주고 목록의 끝에 배열의 끝임을 알리는 nil 을 넣는다. 이것이 배열의 중간에 nil 을 저장할 수 없는 이유 중의 하나이다.

NSArray *array;

array = [NSArray arrayWithObject: @"one", "two", "three", "four", nil];




배열을 만들고 나면 다음과 같이 배열이 담고 있는 객체의 개수를 얻을 수 있다.

- (unsigned) count;

ex) [array count];




다음과 같이 특정 인덱스의 객체를 가져올 수 있다.

- (id) objectAtIndex: (unsigned int) index;

ex) [array objectAtIndex: 1];




다음 코드는 위의 메소드를 이용해서 작성하였다.


int i;

NSArray *array;

array = [NSArray arrayWithObject: @"one", "two", "three", "four", nil];

for (i = 0; i < [array count]; i++) {

    NSLog(@"index %d has %@.", i, [array objectAtIndex: i] );

}



출처 : Objective-C 2.0 (이종웅 저)

Posted by 놀란