代码的话,创建用:
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0,0,200,80)]]
0,0,200,80自己改合适位置。
vc 里显示用:
[self.view addSubview:button]
响应的话:
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]
buttonClicked 函数记得要写。
第一步:选择UnityAppController.mm这个文件打开。并在int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight, int* openglesVersion)
这个方法里面的
return true之前加入
//创建一个全屏幕的window
CGRect rect=CGRectMake(0, 0, *screenWidth, *screenHeight)
*window=[[UIWindow alloc] initWithFrame:rect]
[*window makeKeyAndVisible]
GLView * view=[[GLView alloc] initWithFrame:rect]
[*window addSubview:view]
[view release]
MyViewController *myView=[[MyViewController alloc] init]
[*window addSubview:myView.view]
[myView release]
其中:MyViewController是导出工程后,手动新建的类,目的是,在这个ViewController种控制u3d模型的旋转、移动等动作。
第二步:创建MyViewController并添加按钮,启动u3d
- (void)viewDidLoad {
[super viewDidLoad]
//创建label视图
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]
//设置显示内容
label.text = @"雨松MOMO的程序世界"
//设置背景颜色
label.backgroundColor = [UIColor blueColor]
//设置文字颜色
label.textColor = [UIColor whiteColor]
//设置显示位置居中
label.textAlignment = UITextAlignmentCenter
//设置字体大小
label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:10] size:20]
//创建按钮
UIButton *button0 = [UIButton buttonWithType:1]
//设置按钮范围
button0.frame = CGRectMake(0, 40, 100, 30)
//设置按钮显示内容
[button0 setTitle:@"矩形左旋转" forState:UIControlStateNormal]
//设置按钮改变后 绑定响应方法
[button0 addTarget:self action:@selector(LeftButtonPressed) forControlEvents:UIControlEventTouchUpInside]
//创建按钮
UIButton *button1 = [UIButton buttonWithType:1]
//设置按钮范围
button1.frame = CGRectMake(0, 100, 100, 30)
//设置按钮显示内容
[button1 setTitle:@"矩形右旋转" forState:UIControlStateNormal]
//设置按钮改变后 绑定响应方法
[button1 addTarget:self action:@selector(RightButtonPressed) forControlEvents:UIControlEventTouchUpInside]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)