前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios开发基础知识 - 2

ios开发基础知识 - 2

作者头像
用户1172164
发布2018-01-16 12:03:50
4710
发布2018-01-16 12:03:50
举报

移动物体

代码语言:javascript
复制
CABasicAnimation *theAnimation;    
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=1;
theAnimation.repeatCount=2;
theAnimation.autoreverses=YES;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:-60];
[view.layer addAnimation:theAnimation forKey:@"animateLayer"]; 

参考:

Field Key Path

Description

rotation.x

The rotation, in radians, in the x axis.

rotation.y

The rotation, in radians, in the y axis.

rotation.z

The rotation, in radians, in the z axis.

rotation

The rotation, in radians, in the z axis. This is identical to setting the rotation.z field.

scale.x

Scale factor for the x axis.

scale.y

Scale factor for the y axis.

scale.z

Scale factor for the z axis.

scale

Average of all three scale factors.

translation.x

Translate in the x axis.

translation.y

Translate in the y axis.

translation.z

Translate in the z axis.

translation

Translate in the x and y axis. Value is an NSSize or CGSize.

访问别的类的属性或者方法

代码语言:javascript
复制
myAppDelegate *appDelegate
     = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
[[[appDelegate rootViewController] flipsideViewController] myMethod];

遍历子视图

代码语言:javascript
复制
for (UIImageView *anImage in [self.view subviews]) {
     if (anImage.tag == 1) {
          // do something
     }
}

播放音乐

代码语言:javascript
复制
	// 设置音乐文件路径
path = [[NSBundle mainBundle] pathForResource:@"mani" ofType:@"mp3"];

	// 判断是否可以访问这个文件
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) 
{    
		// 设置 player
	player = [[AVAudioPlayer alloc] initWithContentsOfURL:
			  [NSURL fileURLWithPath:path] error:nil];
	
		// 调节音量 (范围从0到1)
	player.volume = 0.4f;
	
		// 准备buffer,减少播放延时的时间      
	[player prepareToPlay];
	
		// 设置播放次数,0为播放一次,负数为循环播放
	[player setNumberOfLoops:-1];
	
	[player play];    
	
}	

随机数

rand()

例:

代码语言:javascript
复制
[_cloud02 setFrame:CGRectMake(-1024+rand()%600, -768+rand()%300, 2048, 1536)];
[_cloud01 setFrame:CGRectMake(-1024+rand()%600, -768+rand()%300, 2048, 1536)];

Timer

每秒调用

代码语言:javascript
复制
[NSTimer scheduledTimerWithTimeInterval:1
     target:self
     selector:@selector(myMethod)
     userInfo:nil
     repeats:YES];

如果需要传递参数的话:

代码语言:javascript
复制
[NSTimer scheduledTimerWithTimeInterval:1     target:self
     selector:@selector(myMethod)
     userInfo:myObject
     repeats:YES];
代码语言:javascript
复制
-(void)myMethod:(NSTimer*)timer {
     // Now I can access all the properties and methods of myObject
     [[timer userInfo] myObjectMethod];
}

停止Timer

代码语言:javascript
复制
[myTimer invalidate]; 
myTimer = nil;

时间

代码语言:javascript
复制
CFAbsoluteTime myCurrentTime = CFAbsoluteTimeGetCurrent();

在模拟器里测试 App 的加速度感应功能

在模拟器里可以用鼠标点击模拟 iPhone 的触摸操作,但重力感应(比如用户倾斜机身来操控飞机/赛车)怎么模拟?按住 command 再按左右方向键,就能在电脑模拟器上测试加速度感应了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2011-01-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档