Dev/iOS2011. 10. 5. 14:16

Property 옵션 값들이 계속 헷갈렸었는데....


@property (


  1. atomic OR nonatomic
    1. 이 두 속성중 하나를 선택하는 것으로 기본값은 atomic입니다. 이부분은 멀티스레딩에 관련된 부분으로 보통 nonatomic을 사용합니다. 자세한건 개발자 문서 참고
  2. assign OR retain OR copy
    1. setter에서 객체를 지정 받을때 
      1. assign의 경우 주소값만 지정받고
      2. retain의 경우 기존것을 release후 새로 받은걸 retain합니다.
      3. copy의 경우 기존것을 release후 새로 받은걸 copy합니다.
    2. 이부분은 setter에 관련있고 getter와는 관련 없습니다.
  3. readonly OR 없음
    1. readonly설정되면 setter가 없습니다. 말그대로 읽기 전용이죠


- 참고 - 문씨의블로그 (http://lab.smoon.kr/70)

Posted by 놀란
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/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. 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 놀란