Objective-C講習に戻る

加速度センサについて

 
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 
    // Override point for customization after application launch
	UIAccelerometer *acc;
	acc = [UIAccelerometer sharedAccelerometer];
	acc.updateInterval = 1.0f/ 60.0f;
	[acc setDelegate:self];
 
    [window makeKeyAndVisible];
}
 
 
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
	NSLog(@"%f %f %f", acceleration.x, acceleration.y, acceleration.z);
	CGFloat red = 0.5f + acceleration.x / 2;
	CGFloat green = 0.5f + acceleration.y / 2;
	CGFloat blue = 0.5f + acceleration.z / 2;
 
	if (red > 1.0f) {
		red = 1.0f;
	} else if (red < 0.0f) {
		red = 0.0f;
	}
 
	if (green > 1.0f) {
		green = 1.0f;
	} else if (green < 0.0f) {
		green = 0.0f;
	}
 
	if (blue > 1.0f) {
		blue = 1.0f;
	} else if (blue < 0.0f) {
		blue = 0.0f;
	}
 
	UIColor *color = [[UIColor alloc] initWithRed:red green:green blue:blue alpha:1.0];
	[window setBackgroundColor:color];
}
 

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2010-10-24 (日) 17:14:25 (2528d)