在学习IOS的开发。
初次感觉像VC的文件目录结构。语法是自身独有的结构。
下面看一个例子
self = [super initWithFrame:frame];
if (self) {
isOne = YES;
imgView1 = [[UIImageView alloc] initWithFrame:BIGRECT];
imgView2 = [[UIImageView alloc] initWithFrame:SMALLRECT];
[imgView1 setImage:[UIImage imageNamed:@"btnFTP.png"]];
[imgView2 setImage:[UIImage imageNamed:@"btnNews.png"]];
imgView1.userInteractionEnabled = NO;
imgView2.userInteractionEnabled = NO;
[self addSubview:imgView2];
[self addSubview:imgView1];
[imgView1 release];
[imgView2 release];
}
return self;
本 代码是初始化两个UIVIew的图片,并将这两个图片交给父窗体管理。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIImageView *big = isOne ? imgView1 : imgView2;
UIImageView *little = isOne ? imgView2 : imgView1;
isOne = !isOne;
/*
UITouch *touch = [touches anyObject];
if ([touch phase] != UITouchPhaseBegan) {
return;
}
*/
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
//[imgView setAlpha:(float)isVisible];
[big setFrame:SMALLRECT];
[big setAlpha:0.5];
[little setFrame:BIGRECT];
[little setAlpha:1.0];
[UIView commitAnimations];
[big setAlpha:0.0f];
[[big superview] bringSubviewToFront:big];
}
此段代码是将以上两个imgview做一个动画切换。。。
切换过程中实现淡入淡出的效果。
页面翻转的代码
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[UIView commitAnimations];
}