Как воспроизводить звук, когда пользователь нажимает на вкладку UITabBarController - PullRequest
0 голосов
/ 01 апреля 2011

В моем приложении у меня есть контроллер uitabbar для управления тремя контроллерами представления. Теперь я хочу добавить звук, если пользователь нажал любую из вкладок. Исходный код:

// Declare all three view controllers
nextview *con = [[nextview alloc]init];
nextview1 *con1= [[nextview1 alloc] init];
nextview2 *con2 = [[nextview2 alloc] init]; 
//declare tab barcontroller  
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 480);

// Set each tab to show an appropriate view controller
[tabBarController setViewControllers:[NSArray arrayWithObjects:con,con1,con2, nil]];

Ответы [ 2 ]

1 голос
/ 01 апреля 2011

Установите делегата на UITabBarController и используйте tabBarController:didSelectViewController: (информация здесь ) для воспроизведения вашего звука. Воспроизвести звук на iOS довольно сложно, но Google - ваш друг.

0 голосов
/ 01 апреля 2011

отслеживать кнопку панели вкладок в делегате - tabBarController: didSelectViewController:

и воспроизводите звук с помощью AVAudioPlayer .. код здесь -

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];

    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    audioPlayer.numberOfLoops = -1;

    if (audioPlayer == nil)
        NSLog([error description]);
    else
        [audioPlayer play];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...