2011-03-20 100 views
0

大家好我想模拟器上测试晃动功能 所以在硬件菜单中我选择了Shake Gesture。 但是什么都没发生,有什么不对?iphone模拟器晃动没有功能

欢迎任何评论

感谢

马克

+0

你可以在这里发布一些你的摇动代码吗? – 2011-03-20 11:11:40

回答

0

点击“摆动姿态”在iPhone模拟器无法播放动画,也许这就是为什么它似乎并没有被做什么?

您可以通过在UIResponder子类中实现motionEnded:withEvent:来接收代码中的摇动事件通知。例如,如果你创建一个自定义UIWindow子类:

// ShakeWindow.h 
@interface ShakeWindow : UIWindow 
@end 

// ShakeWindow.m 
#import "ShakeWindow.h" 

@implementation ShakeWindow 

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { 
    if (motion == UIEventSubtypeMotionShake) { 
    NSLog(@"Shake!"); 
    } 
} 

@end 

欲了解更多信息,请参阅苹果的事件处理指南适用于iOS的Motion Events部分。

0
-(void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self becomeFirstResponder]; 
} 

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { 

    if (motion == UIEventSubtypeMotionShake) { 
     NSLog(@"shake"); 
     //your code 
    } 

}