如何通过Xcode Designer添加MPVolumeView? [英] How to add the MPVolumeView via Xcode Designer?

查看:109
本文介绍了如何通过Xcode Designer添加MPVolumeView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初在页面上动态添加了一个MPVolumeView ...

I originally added an MPVolumeView dynamically on to a page...

#import "MediaPlayer/MPVolumeView.h"
.
.
-(IBAction) handleVolumeButtonClicked:(id) sender {
    if (volumeView == nil) {
        volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(25, 378, 270, 30)];
        [self.view addSubview:volumeView];
        [volumeView release];
    } else {
        [volumeView removeFromSuperview];
        volumeView = nil;
    }
}

但是由于某种原因,我开始得到应用程序的报告

But for some reason I started getting reports of the application crashing when dynamically adding the volume component.

为了解决这个问题,我决定尝试通过XCode设计器将该组件添加到视图中,然后我意识到我不知道如何做到这一点!

To work around this, I decided to try and add the component to the view via the XCode designer, but then I realised that I didn't know how to do this!

我先将一个对象从模板拖动到对象调色板,但后来发现我无法添加到视图。所以我废除了这个想法,然后直接拖动'View'对象到.xib视图。

I dragged an 'Object' from the template to the Object palette first, but then I found that I couldn't add it to the view. So I scrapped that idea and then dragged the 'View' object directly on to the .xib view.

添加组件后,我试图将自定义类更改为MPVolumeView,但视图只是呈现了一个空的矩形。在模拟器中运行代码不能呈现任何东西。

Once the component was added, I tried to change the 'Custom Class' to 'MPVolumeView', but the view just rendered an empty rectangle. Running the code in the simulator failed to render anything.

有没有人知道我缺少什么步骤来添加一个类到调色板中不存在的视图? / p>

Does anyone know what steps I am missing to add a class to the view that doesnt already exist in the palette?

推荐答案

不知道如果你现在已经想出了这一点。我刚刚创建了一个应用程序与卷滑块成功。这是我做的(从 MPVolumeView ):

Not sure if you have figured this out by now. I just created an app with a volume slider successfully. Here's what I did (from MPVolumeView):


  • 添加了UIView,并根据需要将其大小和位置放置到.xib视图中。

  • 将类更改为 MPVolumeView

  • 将以下内容添加到我的.h文件中:



    • Added a UIView and sized and positioned it as desired into the .xib view.
    • Changed the Class to MPVolumeView
    • Added the following to my .h file:
    #import 
    
    @interface MyView : UIViewController {
        MPVolumeView *_mpVolumeViewParentView;
    }
    @property (nonatomic, retain) IBOutlet MPVolumeView *mpVolumeViewParentView;
    
    @end




    • 将以下内容添加到我的.m文件:

    • #import "MyView.h"
      
      @implementation MyView
      
      @synthesize mpVolumeViewParentView = _mpVolumeViewParentView;
      
      - (void)viewDidLoad {
          [super viewDidLoad];
          [[self mpVolumeViewParentView] setBackgroundColor:[UIColor clearColor]];
          MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame:[[self mpVolumeViewParentView] bounds]];
          [[self mpVolumeViewParentView] addSubview:myVolumeView];
          [myVolumeView release];
      }
      - (void)dealloc {
          [_mpVolumeViewParentView release];
          [super dealloc];
      }

      希望它有帮助。

      这篇关于如何通过Xcode Designer添加MPVolumeView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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