나는 UIImageviews의 레이어를 약간 이동하여 약간의 깊이 인식을 얻는 데 사용하는 가속도계가 있습니다.가속도계의 성능 문제
여기 내 viewdidload 메서드 내에서 애니메이션과 가속도계를 인스턴스화하는 데 사용하는 코드입니다. 아이 패드가 성능 문제가 발생하기 시작하면서, 후행 시작 후
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
self.difference = 0 - acceleration.y;
if (fabsf(self.difference) > 0.01) {
for (int i = 0; i < self.accLayerPoints0.count; i++) {
NSValue *val = [self.accLayerPoints0 objectAtIndex:i];
CGPoint origin = [val CGPointValue];
float x = origin.x + (acceleration.y * ACC_LAYER0_THRESHOLD);
[animateLayer0 setToValue:[NSValue valueWithCGPoint:CGPointMake(x, origin.y)]];
UIImageView *layer0 = [self.accLayerObjects0 objectAtIndex:i];
[layer0.layer addAnimation:animateLayer0 forKey:nil];
}
for (int i = 0; i < self.accLayerPoints1.count; i++) {
NSValue *val = [self.accLayerPoints1 objectAtIndex:i];
CGPoint origin = [val CGPointValue];
float x = origin.x + (acceleration.y * ACC_LAYER1_THRESHOLD);
[animateLayer1 setToValue:[NSValue valueWithCGPoint:CGPointMake(x, origin.y)]];
UIImageView *layer0 = [self.accLayerObjects1 objectAtIndex:i];
[layer0.layer addAnimation:animateLayer1 forKey:nil];
}
for (int i = 0; i < self.accLayerPoints2.count; i++) {
NSValue *val = [self.accLayerPoints2 objectAtIndex:i];
CGPoint origin = [val CGPointValue];
float x = origin.x + (acceleration.y * ACC_LAYER2_THRESHOLD);
[animateLayer2 setToValue:[NSValue valueWithCGPoint:CGPointMake(x, origin.y)]];
UIImageView *layer0 = [self.accLayerObjects2 objectAtIndex:i];
[layer0.layer addAnimation:animateLayer2 forKey:nil];
}
}
}
내 문제는 : 여기
UIAccelerometer *accelerator = [UIAccelerometer sharedAccelerometer];
accelerator.delegate = self;
accelerator.updateInterval = 0.1f;
animateLayer0 = [CABasicAnimation animationWithKeyPath:@"position"];
animateLayer1 = [CABasicAnimation animationWithKeyPath:@"position"];
animateLayer2 = [CABasicAnimation animationWithKeyPath:@"position"];
animateLayer0.duration = 0.1;
animateLayer0.fillMode = kCAFillModeForwards;
animateLayer0.removedOnCompletion = false;
animateLayer1.duration = 0.1;
animateLayer1.fillMode = kCAFillModeForwards;
animateLayer1.removedOnCompletion = false;
animateLayer2.duration = 0.1;
animateLayer2.fillMode = kCAFillModeForwards;
animateLayer2.removedOnCompletion = false;
는 가속도계 기능의 코드입니다. Allocations 도구를 사용하여 문제를 일으키는 가속도계 기능의 코드인지 확인했습니다.
더 이상 사용하지 않는 객체를 해제하거나 코드를 삭제할 수있는 방법이 있습니까? 나는 ARC를 사용하고있어 청소 방법이 확실하지 않습니다.
GCD에 대한 몇 가지 검색을 수행했으며 NSOperation에 대한 많은 참고 자료를 발견했습니다. 왜 대신 GCD에 대해 언급 했습니까? 또한 나는이 두 가지가 어떻게 작용 하는지를 알아낼 수 없다. (여전히 멍청한 놈) 나에게 내 대답으로 이어질 좋은 튜토리얼을 알고 계신가요? – Fellowsoft
GCD를 사용하면 예약 작업을보다 세밀하게 제어 할 수 있습니다. 당신은 문서로 잠수하고 당신이 별도로 가지고있는 특정 질문을 게시해야 할 것입니다. 위의 방법은 일반적으로 이동하는 방법이지만 정확하게 구현하는 방법은 단일 응답에 맞추기에는 너무 광범위합니다. –