菜鸟教程小白 发表于 2022-12-12 13:38:12

iphone - 我无法在我的设备上摇晃/移动


                                            <p><p>这是我的代码。</p>

<pre><code>-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [ addObserver:self
                                             selector:@selector(shake) name:@&#34;shake&#34; object:nil];
    if(event.type == UIEventTypeMotion &amp;&amp; event.subtype == UIEventSubtypeMotionShake)
    {

       // SOMETHING HERE
    }
            NSLog(@&#34;motion Began&#34;);
    }
   else
    {
      NSLog(@&#34;Shake Is Over&#34;);
    }
}
</code></pre>

<p>我想在我的设备上摇晃/运动。我使用了该代码,但它不起作用..</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>写下下面的代码...然后检查</p>

<pre><code>-(BOOL) canBecomeFirstResponder {

return YES;

}

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

}

-(void)viewDidAppear:(BOOL)animated {

;

}

-(void)viewDidDisappear:(BOOL)animated {

;

}
</code></pre>

<p>让我知道它是否有效!!!</p>

<p>编码愉快!!!!</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 我无法在我的设备上摇晃/移动,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18285350/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18285350/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 我无法在我的设备上摇晃/移动