gpt4 book ai didi

ios - 将 MPVolumeView 添加到底部工具栏

转载 作者:行者123 更新时间:2023-11-29 11:05:50 24 4
gpt4 key购买 nike

我正在尝试将 MPVolumeView 的实例添加到我的导航 Controller 的底部栏。(工具栏的框已打勾)我的代码没有出现任何错误,但是当我在我的设备上运行项目时,音量 slider 没有显示。在此先感谢您的任何建议,这是我的代码:

@interface ViewController ()
{
AVPlayer *vPlayer;
AVPlayerItem *playerItem;
UISegmentedControl *segm;
UIToolbar *toolbar;
}
@end

@implementation ViewController
@synthesize myViewVolume;
@synthesize nowPlaying;

- (void)viewDidLoad
{
[super viewDidLoad];
playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://vibesradio.org:8000 /listen.pls"]];
vPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:NULL];


//self.myViewVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(20, 330, 280, 50)];


self.myViewVolume = [[MPVolumeView alloc] initWithFrame: toolbar.bounds];
[self.myViewVolume sizeToFit];
[self.view addSubview:toolbar];
[toolbar addSubview:self.myViewVolume];

}

最佳答案

您不能将 subview 添加到工具栏。您必须添加一个 UIBarButtonItem,其 View 是您要显示的 View 。

UIBarButtonItem* b = [[UIBarButtonItem alloc] initWithCustomView: myVolumeView];
myToolbar.items = @[b];

这与 MPVolumeView 无关。对于要添加到工具栏或导航栏的任何任意 View 都是如此。

这是在我的设备上用于导航界面中的 View Controller 的实际代码:

MPVolumeView* vv = [[MPVolumeView alloc] initWithFrame: CGRectMake(0, 0, 150, 40)];
UIBarButtonItem* b = [[UIBarButtonItem alloc] initWithCustomView: vv];
self.toolbarItems = @[b];
self.navigationController.toolbarHidden = NO;

另请注意,您必须在设备上进行测试;模拟器中没有体积 View 的界面。 :(

关于ios - 将 MPVolumeView 添加到底部工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13664033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com