Unity 3D 添加ios视图

Untiy导出的ios都是单视图的程序,如果要在这个视图上添加其他视图的方法:

- ( void) applicationDidFinishLaunching:(UIApplication*)application
{
    printf_console( " -> applicationDidFinishLaunching()\n ");

     if ([UIDevice currentDevice].generatesDeviceOrientationNotifications == NO)
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [self startUnity:application];
    //添加自己的视图,记得在release掉myView
     myView=[[myViewController alloc]init];
    [application.keyWindow addSubview:myView.view];

}

如果要在myView中执行其他操作,就要使用通知方法,因为你没有办法把myView设置为代理类。

- ( void)viewDidLoad {
    // 添加接收通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addbtns:) name: @" showbtns "  object:nil];
    [self.view setFrame:CGRectMake( 0000)];
    [super viewDidLoad];
}

 -( void)addbtns:(NSNotification *)notification
{
    play=YES;
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake( 101010030)];
    [btn setTitle: @" 滚动 " forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor brownColor]];
    [btn addTarget:self action:@selector(StartTimer) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [self.view setFrame:CGRectMake( 0030050)];
}

然后在程序其他地方发出通知,一般是untiy接口函数发出通知,因为untiy导出的是单视图,一开始根本没有其他视图或程序发出通知

extern  " C " {
     void IOSExcuteFucntion( const  char* functionName, const  char* arg)
    {
         if (delegateObject == nil)
          delegateObject = [[UnityExcuteDelegate alloc] init];
        NSString *funnameString=[CreateNSString(functionName) stringByAppendingFormat: @" : "];
        NSString *funartString=CreateNSString(arg);
        [delegateObject performSelector:NSSelectorFromString(funnameString) withObject:funartString];
         // [delegateObject performSelector:(SEL)(method)];
        
// objc_msgSend(delegateObject, (SEL)method);
            
    }
    
}

@implementation UnityExcuteDelegate

- ( id)init
{
    self = [super init];
     return self;
}
-( void)dealloc
{
    [super dealloc];
}


-( void)test_function:(NSString *)str
{
     // 发出通知
    [[NSNotificationCenter defaultCenter]postNotificationName: @" showbtns "  object:self userInfo:nil];
    
}
@end 

转载于:https://www.cnblogs.com/bandy/archive/2012/04/01/2428275.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值