单击链接后,iPhone MotionShake停止工作

时间:2011-06-23 01:36:15

标签: iphone objective-c xcode cocoa-touch uiwebview

我有一个应用程序,在用户摇动手机后显示UIWebView。它完美无缺,直到用户点击webview中的链接。用户单击链接后,必须单击屏幕中的空白区域才能使摇动功能重新开始工作。

如下所示,我已经包含了canBecomeFirstResponder和webViewDidFinishLoad函数。请帮忙!

#import "phonetiltViewController.h"

@implementation phonetiltViewController

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

-(void)viewDidDisappear:(BOOL)animated {
    [self resignFirstResponder];
}

- (BOOL)canBecomeFirstResponder 
{    // Shake gesture pops to top. If you don't want this override and 
    return YES; 
} 

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.subtype == UIEventSubtypeMotionShake) {
        [webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.google.com"]]];
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self becomeFirstResponder];
}

1 个答案:

答案 0 :(得分:0)

然后尝试UIAccelerometer。您可以像这样使用其委托方法

- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration{
if(acceleration.x>1.5 || acceleration.y>1.5 || acceleration.z>1.5){
//load page}