둥근 모서리가있는 사각형을 그리고 검은 색으로 채우기 위해 간단한 UIView 확장에서 drawRect 메서드를 재정의하고 터치하여 크기를 조정하도록보기를 애니메이션화하려고했습니다. 상황에 따라 전체 크기가 동일하게 유지되는 것처럼 크기를 변경하면 도면이 완전히 변형됩니다. drawRect는 애니메이션 중에는 호출되지 않습니다. 그러나 애니메이션 뒤에 그림을 그리라고 지시하면 올바르게 그려집니다.iOS UIView drawRect 크기 조정 애니메이션
드로잉을 변형시키지 않고 리사이징을 어떻게 애니메이트 할 수 있습니까?
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat radius = rect.size.height * 0.5f;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPathAddArcToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMinY(rect),
CGRectGetMaxX(rect), CGRectGetMaxY(rect), radius);
CGPathAddArcToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMaxY(rect),
CGRectGetMinX(rect), CGRectGetMaxY(rect), radius);
CGPathAddArcToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMaxY(rect),
CGRectGetMinX(rect), CGRectGetMinY(rect), radius);
CGPathAddArcToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMinY(rect),
CGRectGetMaxX(rect), CGRectGetMinY(rect), radius);
CGPathCloseSubpath(path);
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextAddPath(context, path);
CGContextFillPath(context);
CGContextRestoreGState(context);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:1.f animations:^{
self.frame = CGRectInset(self.frame, 0.f, -100.f);
}];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:1.f animations:^{
self.frame = CGRectInset(self.frame, 0.f, +100.f);
}];
}
I 추측을 가져온 http://www.nomadplanet.fr/2010/11/animate-calayer- coreanimation과 함께 사용자 정의 속성/ – Jonny