0

我有 EAGLView,它是 UIButton。在 ViewController 中,我需要在横向模式下显示与 EAGLView 中的单击事件相同的按钮。我试图设置 [eaglView.save setFrame:CGRectMake(360, 10, 40, 40)]; 但横向尺寸没有变化,仍然显示纵向模式框架。

EAGLView.h:

@interface BooksEAGLView : UIView{

  UIButton *save;

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

EAGLView.mm:

 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];

视图控制器.mm:

 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 {

}

}

}
4

4 回答 4

0

书籍EAGLEView.m

#import "BooksEAGLView.h"

@implementation BooksEAGLView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        save=[UIButton buttonWithType:UIButtonTypeCustom];
        [save setFrame:CGRectMake(240, 10, 50, 50)];
        [save setBackgroundColor:[UIColor redColor]];
        [save setTitle:@"Save" forState:UIControlStateNormal];
        [save addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:save];
    }
    return self;
}
-(void)save:(id)sender
{
    NSLog(@"clicked...");
}
于 2014-06-09T12:35:51.580 回答
0

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

- (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)];
    }


}
于 2014-06-09T09:53:38.943 回答
0

请参考此代码

#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)];
    }


}
于 2014-06-09T12:29:19.150 回答
0

书籍EAGLEView.h

#import <UIKit/UIKit.h>

@interface BooksEAGLView : UIView{

    UIButton *save;

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

@end
于 2014-06-09T12:32:26.607 回答