我有一个简单的应用程序,它包含 2 个视图。顶视图有一个加速度计代表。当用户在屏幕上显示顶视图时摇晃时。然后调用 pushviewcontroller 并出现子视图。问题是当子视图出现时,我摇晃它,它仍然捕捉到摇晃动作并导致我出错。所以帮助我。提前致谢。
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
const float violence = 1.2;
static BOOL beenhere;
BOOL shake = FALSE;
if (beenhere) return;
beenhere = TRUE;
if (acceleration.x > violence || acceleration.x < (-1* violence))
shake = TRUE;
if (acceleration.y > violence || acceleration.y < (-1* violence))
shake = TRUE;
if (acceleration.z > violence || acceleration.z < (-1* violence))
shake = TRUE;
if (shake) {
[self playSound:@"suzu"];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"noVib"] == NO) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
[self presentModalViewController:mMoviePlayer animated:YES];
[self play];
}
当调用播放方法并且视频播放完毕时,将调用 pushviewcontroller 并出现子视图
下面是一个处理所有电影播放器内容的类。
- (void) initPlayer{
if (mMoviePlayer != nil){
[mMoviePlayer release];
}
mMoviePlayer = [[MoviePlayerViewController alloc] initWithContentURL:[self createURL]];
[[NSNotificationCenter defaultCenter] removeObserver:mMoviePlayer
name:MPMoviePlayerPlaybackDidFinishNotification object:mMoviePlayer.moviePlayer];
[mMoviePlayer.moviePlayer setShouldAutoplay:NO];
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
mMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
mMoviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer.moviePlayer];
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer.moviePlayer];
[self dismissModalViewControllerAnimated:YES];
[mMoviePlayer release];
mMoviePlayer = nil;
[self toNext];
}