我正在构建收音机APP,我已将UIView添加到我的ViewController并将其类更改为MPVolumeView。当我在我的设备上测试时,滑块出现,但对触摸手势没有响应。奇怪的是,它通过音量按钮响应硬件变化。这是我的代码:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController : UIViewController{
MPVolumeView *_mpVolumeView;
}
- (IBAction)playPressed:(id)sender;
@property (strong, nonatomic) IBOutlet MPVolumeView *mpVolumeView;
而m。文件:
@interface ViewController ()
{
AVPlayer *vPlayer;
}
@end
@implementation ViewController
@synthesize mpVolumeView = _mpVolumeView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *vibes = [NSURL URLWithString:@"http://vibesradio.org:8002/listen.pls"];
vPlayer = [[AVPlayer alloc] initWithURL:vibes];
_mpVolumeView.backgroundColor = [UIColor clearColor];
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: _mpVolumeView.bounds];
[_mpVolumeView addSubview:myVolumeView];
}
感谢您提供解决此问题的任何提示和建议。我花了几个小时试图找到一个没有运气的解决方案。
答案 0 :(得分:0)
您可能想要更改:
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: _mpVolumeView.bounds];
[_mpVolumeView addSubview:myVolumeView];
朝向:
self.myVolumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
[self.myVolumeView sizeToFit];
[self.view addSubview:self.myVolumeView];