- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
/*摇一摇
需要这个controller本身支持摇动(好像不需要)
同时让他成为第一响应者
*/
NSLog(@"支持摇动否?%d",[UIApplication sharedApplication].applicationSupportsShakeToEdit);
//配置支持摇动
// [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110, 100, 100, 40)];
label.text = @"摇一摇";
[self.view addSubview:label];
[label release];
}
/*
*因为大部分ViewController的canBecomeFirstResponder是NO
*/
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//成为第一响应者
[self becomeFirstResponder];
}
- (void)viewDidDisappear:(BOOL)animated
{
//取消第一响应者
[self resignFirstResponder];
[super viewDidDisappear:animated];
}
#pragma mark - 实现摇一摇的方法
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//检测到摇动
if (motion == UIEventSubtypeMotionShake) {
NSLog(@"摇动......");
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:second animated:YES];
[second release];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
NSLog(@"cancel shake...");
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
NSLog(@"finish shake...");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}