DAY ELEVEN – PlumbBob
今天来建立一个 iPhone app 软件,用你的iPhone 当作测量水平器。
纲要:
- 在程序显示前运行代码 -
- 加入QUartzCore Frameworks -
- 关于iPhone的“Utility Application” 运用 -
- UIAccelerometer (加速度检波器) 代码运用 -
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> Utility Application
命名 : 我这里命名为 “PlumbBob”
(1)
(2) 导入下面图片文件
下载下面图片,放入 PlumbBob 文件夹内并命名为下面名称
PlumbBob.png
在xCode下右键点击 PlumbBob->Add->Existing Files; 在 PlumbBob 文件夹内,选择下载好的图片,按 Add
(3)
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController <UIAccelerometerDelegate> {
}
- (void)rotatePlumbStringToDegre
@end
CGFloat DegreesToRadians(CGFloat degrees);
CGFloat RadiansToDegrees(CGFloat radians);
(4)
#import "MainViewController.h"
#import "MainView.h"
#import <QuartzCore/QuartzCore.h>
// Constant for the number of times per second (Hertz) to sample acceleration.
#define kAccelerometerFrequency 40
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterf
}
- (void)didReceiveMemoryWarning {
}
- (void)dealloc {
}
#pragma mark -
#pragma mark === Accelerometer delegate ===
#pragma mark -
// UIAccelerometerDelegate method, 当设备加速时呼出.
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
}
#pragma mark -
#pragma mark === Swing the plumb and string ===
#pragma mark -
- (void)rotatePlumbStringToDegre
}
@end
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
CGFloat RadiansToDegrees(CGFloat radians) {return radians * 180/M_PI;};
最后在 xCode 选择 Build->Build and Go; Save All.