在TabBar控制的iOS应用中的第二个选项卡中进行交互时,将RemoteControlEvents接收到第一个选项卡 [英] Receiving RemoteControlEvents to First Tab when interacting in Second Tab in a TabBar Controlled iOS App

查看:220
本文介绍了在TabBar控制的iOS应用中的第二个选项卡中进行交互时,将RemoteControlEvents接收到第一个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发带有标签栏控制器的iOS应用.在第一个选项卡中,我放置了一个AVQueuePlayer实例以开始从Web播放音乐.我做了所有编码,以允许通过远程控制事件播放和暂停事件.但是,只有当我停留在第一个选项卡中时,我才能接收远程控制事件.当我切换到其他选项卡时,第一个选项卡不会收到远程控制事件.

I am developing an iOS app with a tab bar controller. In the first tab, I placed an instance of AVQueuePlayer to start playing music from the web. I did all coding to allow play and pause events through remote control events. But I could able to receive remote control events only when I stay in the first tab. When I switch to other tabs, remote control events are not received to the first tab.

当将以下几行放在第一个选项卡视图控制器中时,即使我停留在第二个选项卡中,我也可以接收到第一个选项卡的远程控制事件.

When I place the following lines in first tab view controller, I can receive remote control events to first tab even when I stay in second tab.

- (BOOL)canResignFirstResponder
{
    return NO;
}

但是我在其他视图中有一些文本字段,用户必须与之交互.通过不在第一选项卡中辞职的第一响应者,我无法在其他选项卡中输入文本.

But I have some text fields in other views with which the user has to interact. By not resigning first responder in first tab, I cannot input text in other tabs.

请帮助我,当用户与第二个选项卡中的应用交互时,如何处理远程事件以控制第一个选项卡中的AVQueuePlayer实例?

Please help me how can I handle remote control events to control an AVQueuePlayer instance in first tab while my user interacts with the app in second tab ?

感谢您的帮助!

推荐答案

确定.我自己想通了.

我在实现文件的开头为avqueueplayer创建了一个全局变量. 在viewDidLoad方法中分配并启动了AVQueuePlayer. 创建了一个类方法来处理播放和暂停时的操作. 并在其他视图控制器中称为此类方法,以直接从这些视图控制器处理远程控制事件.这是我编码的示例:

I created a global variable for the avqueueplayer in the starting of the implementation file. Allocated and initiated the AVQueuePlayer in viewDidLoad method. Created a class method to handle what to do in the event of play and pause. And called this class method in other view controllers to handle the remote control events directly from those view controllers. Here is a sample of what I coded:

//playerView header file

@interface playerView : UIViewController

+ (void)togglePlayPause;

@end

//playerView Implementation File

#import "playerView.h"

@interface playerView ()
@end

@implementation playerView

AVQueuePlayer *player;

- (void)viewDidLoad
{
[super viewDidLoad];
player = [[AVQueuePlayer alloc] initWithPlayerItem:[AVPlayerItem playerItemWithURL: someurl]];
}

+ (void) togglePlayPause
{
    if (player.rate == 1.0)
    {
        [player pause];
    }
    else if ((player.rate == 0.0) && ([player status]!= 2))
    {
        [player play];
    }
}

// include all other methods to handle remote control events as laid in apple documentation

@end



//otherView Implementation file

#include "playerView.h"


@interface otherView ()

@end

@implementation otherView

// include all other methods to handle remote control events as laid in apple documentation

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent
{

    if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {
            case UIEventSubtypeRemoteControlTogglePlayPause:
                [playerView togglePlayPause];
                break;
            default:
                break;
        }
    }
}

@end

有关Apple文档中规定的其他所有处理远程控制事件的方法,请参考:

For all other methods to handle remote control events as laid in apple documentation refer to:

iOS事件处理指南-远程多媒体控制

这篇关于在TabBar控制的iOS应用中的第二个选项卡中进行交互时,将RemoteControlEvents接收到第一个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆