开发者

iPhone MotionShake Stops Working After Clicking Link

开发者 https://www.devze.com 2023-03-14 16:09 出处:网络
I have an app that displays a UIWebView after the user shakes the phone.It works perfectly until the user clicks a link in the webview.Once the user clicks a link, they must click white space in the s

I have an app that displays a UIWebView after the user shakes the phone. It works perfectly until the user clicks a link in the webview. Once the user clicks a link, they must click white space in the screen to get the shake function to start working again.

As you can see below, I have 开发者_JAVA技巧included both the canBecomeFirstResponder, and the webViewDidFinishLoad functions. Please help!

#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];
}


Then try UIAccelerometer. You can use its delegate method like this

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

精彩评论

暂无评论...
验证码 换一张
取 消