//
// UIView+CL.h
//
// Created by wangsoko on 11-10-29.
// Copyright 2011 ChipLife. All rights reserved.
//
@interface UIView (CL)
- (void)rotate:(CGFloat)degree animated:(BOOL)animated;
@end
//
// UIView+CL.m
//
// Created by wangsoko on 11-10-29.
// Copyright 2011 ChipLife. All rights reserved.
//
#import "UIView+CL.h"
- (void)rotate:(CGFloat)degree animated:(BOOL)animated {
// Calculates new center point.
CGFloat x = self.bounds.size.width / 2.0;
CGFloat y = self.bounds.size.height / 2.0;
CGPoint center = CGPointMake(y, x);
// Sets the new center point.
self.center = center;
if (animated) {
[UIView beginAnimations:nil context:nil];
}
// Rotate the view around the new center point.
CGAffineTransform transform = self.transform;
transform = CGAffineTransformRotate(transform, (M_PI * degree / 180));
self.transform = transform;
if (animated) {
[UIView commitAnimations];
}
}