首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将EAGLView UIButton框架传递给视图控制器

如何将EAGLView UIButton框架传递给视图控制器
EN

Stack Overflow用户
提问于 2014-06-09 16:40:53
回答 4查看 120关注 0票数 0

我有EAGLView,它是UIButton。在ViewController中,我需要在横向模式下显示与单击事件相同的按钮,就像它在EAGLView中一样。我试着设置了eaglView.save setFrame:CGRectMake(360,10,40,40);但它的大小在横向模式下没有变化,它仍然显示纵向模式的边框。

EAGLView.h:

代码语言:javascript
复制
@interface BooksEAGLView : UIView{

  UIButton *save;

 }
 @property(nonatomic, retain) UIButton *save;

EAGLView.mm:

代码语言:javascript
复制
 save=[UIButton buttonWithType:UIButtonTypeCustom];
 [save setImage:[UIImage imageNamed:@"share_1.png"] forState:UIControlStateNormal];
 [save setFrame:CGRectMake(240, 10, 40, 40)];
 [save addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside];
 [self addSubview:save];

Viewcontroller.mm:

代码语言:javascript
复制
 eaglView = [[BooksEAGLView alloc] initWithFrame:viewFrame delegate:self appSession:vapp];

 [self setView:eaglView];

 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
 {


 if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){


 [eaglView.save setFrame:CGRectMake(360, 10, 40, 40)];



}else {

}

}

}
EN

回答 4

Stack Overflow用户

发布于 2014-06-09 17:53:39

将以下代码放入您调用BooksEAGLView的视图控制器中

代码语言:javascript
复制
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{


    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        [eaglView.save setFrame:CGRectMake(360, 10, 40, 40)];

    }else {
         [eaglView.save setFrame:CGRectMake(240, 10, 50, 50)];
    }


}
票数 0
EN

Stack Overflow用户

发布于 2014-06-09 20:29:19

请参考此代码

代码语言:javascript
复制
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    eaglView = [[BooksEAGLView alloc] initWithFrame:CGRectMake(100, 100, 150, 200)];

    [self setView:eaglView];

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)  interfaceOrientation duration:(NSTimeInterval)duration
{


    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        [eaglView.save setFrame:CGRectMake(360, 10, 40, 40)];

    }else {
         [eaglView.save setFrame:CGRectMake(240, 10, 50, 50)];
    }


}
票数 0
EN

Stack Overflow用户

发布于 2014-06-09 20:32:27

BooksEAGLEView.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface BooksEAGLView : UIView{

    UIButton *save;

}
@property(nonatomic, retain) UIButton *save;

@end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24116578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档