반응형

Objective C 9

[iOS Objective c] 화면 흔들기 (view shake) 구현

[iOS Objective c] 화면 흔들기 (view shake) 구현 setDuration : 애니메이션 실행 시간setRepeatCount : 애니메이션 실행 횟수 setFromValue : 애니메이션 시작 위치setToValue : 애니메이션 끝 위치 다음 코드는 0.05초 동안 좌우로 20.0f 씩 4번 흔드는 애니메이션 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation setDuration:0.05]; [animation setRepeatCount:4]; [animation setAutoreverses:YES]; [animation setFromValue:[NSValue val..

[iOS] NSMutableArray 배열 순서 섞기

[iOS] NSMutableArray 배열 순서 섞기 (랜덤으로 섞기) [Objective-c] for (int i=0; i < [arrTestA count]; i++) { int random = arc4random() % [arrTestA count]; [arrTestA exchangeObjectAtIndex:random withObjectAtIndex:i]; } 만약 특정 인덱스는 섞으면 안될 경우 아래 코드를 추가해주자. if (random == 5 || i == 5) { continue; } [Swift] extension Array { mutating func suffle() { if count < 2 { return } for i in 0 ..< (count - 1) { let j = Int(..

[Objective-C] alloc, init 메서드

ClassA* a = [ClassA alloc]; alloc은 allocate(할당하다)의 줄임말이다. 새로운 클래스에 메모리 공간을 할당하는 것이다. 클래스에 alloc 메세지를 보내, 그 클래스의 새로운 인스턴스를 받는다. alloc 메서드는 객체의 모든 인스턴스 변수를 0으로 초기화한다. 그러나 이것으로 객체가 사용하기에 충분히 초기화되었다고 볼 수는 없다. 따라서 객체를 생성(allocate, 메모리에 할당)한 후, 초기화(initialize)해 주어야 한다. 이것은 다음 명령문으로 수행할 수 있다. a = [a init]; init 메서드는 클래스의 인스턴스를 초기화한다. a 변수에 init 메시지를 보내는 것에 주목하자. 이것은 클래스가 아니라 특정한 ClassA 객체를 초기화하는 것을 뜻한다..

반응형