IOS学习 -两个图片切换显示

在学习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];
		
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机场信息系统研究员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值