IPhone之动画左右旋转
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];
这个属性可以设置动化的旋转方向
?
代码如下:
?
- (void) animationFinished: (id) sender
{
self.navigationItem.rightBarButtonItem =[[[UIBarButtonItem alloc] initWithTitle:@"11" style:UIBarButtonItemStylePlain target:self action:@selector(flip:)] autorelease];
}
?
- (void) flip: (id) sender
{
// 隐藏右侧按钮
self.navigationItem.rightBarButtonItem = nil;
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
//获取移动的view
UIView *whiteBackdrop = [self.view viewWithTag:100];
// 选择是左移还是右移
if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex])
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];
else
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:whiteBackdrop cache:YES];
NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];
NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];
[whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
[UIView commitAnimations];
}
- (void)loadView
{
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"11" style:UIBarButtonItemStylePlain target:self action:@selector(flip:)] autorelease]; //BARBUTTON(@"Flip",);
?
?
// 设置分段控件 标题
UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:[@"左转 右转" componentsSeparatedByString:@" "]] autorelease];
seg.selectedSegmentIndex = 0;
seg.segmentedControlStyle = UISegmentedControlStyleBar;
self.navigationItem.titleView = seg;
//设置转向的view
UIView *view100=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 480)];
view100.tag=100;
view100.backgroundColor=[UIColor blueColor];
self.view=view100;
}