ios 美元飘落效果的demo

demo功能:ios 美元飘落效果的demo 。

demo说明:美元飘落效果demo ,可以多指触控,触控点越多,飘落的美元面额越大。主要代码在:MainView.m中。

demo截屏:


demo代码说明:

- (void)onTimer
{
	UIImageView *dollarView;
	UIImage *dollarImage;
	
	// for effect... make it harder to get some of the other bill index's
	// if it does not pass criteria reset back to 1
	
	// double tap upside down for 5 Dollar bill
	if(billIndex > 2) {
		if (deviceTilt.y > 0.5f)
			billIndex = 5;
		else
			billIndex = 1;
	}
	else if(billIndex > 1) {
		if (deviceTilt.x > 0.5f) 
			billIndex = 3;
		else if (deviceTilt.x < -0.5f)
			billIndex = 4;
		else
			billIndex = 2;
			
	}
	 
	
	switch (billIndex) {
		case 2:
			dollarImage = [UIImage imageNamed:@"dol2.png"];
			break;
		case 3:
			dollarImage = [UIImage imageNamed:@"5dol.jpg"];
			break;
		case 4:
			dollarImage = [UIImage imageNamed:@"10dol.jpg"];
			break;
		case 5:
			dollarImage = [UIImage imageNamed:@"20dol.jpg"];
			break;			
		default:
			dollarImage = [UIImage imageNamed:@"dollar.png"];
			break;
	}
	//以上是检测触点,并分配不同的美元图片
	// for effect only draw one 2 dollar bill by resetting billIndex
	if (billIndex == 2)
		billIndex = 1;
	//以下是动画部分的核心代码
	dollarView = [[UIImageView alloc] initWithImage:dollarImage];
	int scale = RANDOM_INT(1, 5);
	int width = 100*scale;
	int height = 44*scale;
	if(useEmitterRect) {
		dollarView.frame = emitterRect;
	//} else if (deviceTilt.x > 0.5f || deviceTilt.y > 0.5f || deviceTilt.x < -0.5f || deviceTilt.y < -0.5f) {
	} else if (deviceTilt.y > 0.5f) {
		dollarView.frame = CGRectMake(160 - (width/2), 490, width, height);
	} else if (deviceTilt.y < -0.5f) {
		dollarView.frame = CGRectMake(160 - (width/2), -(height+10), width, height);
	} else if (deviceTilt.x > 0.5f) {
		dollarView.frame = CGRectMake(-(width+10), 240-(height/2), width, height);
	} else if (deviceTilt.x < -0.5f) {
		dollarView.frame = CGRectMake(330, 240-(height/2), width, height);
	} else {
		switch (RANDOM_INT(0, 3)) {
			case 0:
				dollarView.frame = CGRectMake(-300, -300, 100*scale, 44*scale);
				break;
			case 1:
				dollarView.frame = CGRectMake(470, -150, 100*scale, 44*scale);
				break;
			case 3:
				dollarView.frame = CGRectMake(470, 630, 100*scale, 44*scale);
				break;			
			default:
				dollarView.frame = CGRectMake(-150, 630, 100*scale, 44*scale);
				break;
		}
	}
	
	[self addSubview:dollarView];
	if(helpView)
		[self bringSubviewToFront:helpView];
	
	[UIView beginAnimations:nil context:dollarView];
	[UIView setAnimationDuration:2];


	dollarView.frame = CGRectMake(RANDOM_INT(-50, 370), RANDOM_INT(-25, 665), 100, 44);
		
	int radians = RANDOM_INT(0, 360) * 0.0174532925;		
	[dollarView setTransform:CGAffineTransformMakeRotation(radians)];
	
	[UIView setAnimationDelegate:self];
	[UIView commitAnimations];
	
	billCount++;
	[billList addObject:dollarView];
	if([billList count] >= MAX_BILLS) {
		UIImageView* oldBill = (UIImageView*)[billList objectAtIndex:0];
		[billList removeObjectAtIndex:0];
		
		[UIView beginAnimations:nil context:oldBill];
		
		[UIView setAnimationDuration:2];
		[oldBill setAlpha:0.0];
		
		[UIView setAnimationDelegate:self];
		[UIView setAnimationDidStopSelector:@selector(goPutThemBack:finished:context:)];
		[UIView commitAnimations];
	}
	
}

demo下载地址:http://download.csdn.net/detail/donny_zhang/5603551


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
iOS开发中实现Twitter登录功能的Demo可以按照以下步骤进行: 1. 首先,在Twitter开发者网站上创建一个应用,获取应用的API Key和Secret Key,并将它们添加到项目的Info.plist文件的URL schemes和URL whitelist中。 2. 在AppDelegate中导入Twitter框架并添加以下代码: ```swift import TwitterKit func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { TWTRTwitter.sharedInstance().start(withConsumerKey: "YOUR_API_KEY", consumerSecret: "YOUR_API_SECRET") return true } ``` 3. 在需要实现登录的ViewController中导入Twitter框架并添加以下代码: ```swift import TwitterKit @IBAction func twitterLoginButtonTapped(_ sender: UIButton) { TWTRTwitter.sharedInstance().logIn { (session, error) in if (session != nil) { print("Twitter login successful with user ID: \(session!.userID)") } else { print("Twitter login error: \(error!.localizedDescription)") } } } ``` 在上述代码中,当用户点击Twitter登录按钮时,调用`TWTRTwitter.sharedInstance().logIn`方法会打开Twitter登录界面,用户在该界面上登录成功后,会返回一个session,其中包含用户的userID和token等信息。根据返回的session是否为nil,判断登录是否成功。 注意:在使用此Demo之前,需要在项目的Build Settings中的Other Linker Flags添加`-ObjC`标志,否则可能会出现链接错误。 以上就是实现Twitter登录功能的iOS开发Demo

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值