2014-06-09 77 views
0

我有EAGLView,它是UIButton。在ViewController中,我需要在横向模式下显示相同的按钮,点击事件在EAGLView中有。我尝试设置[eaglView.save setFrame:CGRectMake(360,10,40,40)];但大小仍然没有改变,它仍然显示肖像模式框架。如何将EAGLView UIButton框架传递给视图控制器

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

Viewcontroller.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 { 

} 

} 

} 

回答

0

把下面的代码中的ViewController中,你在呼唤你图书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

相同的代码也使用..检查我的代码在问题.. – user3602987

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


} 
0

BooksEAGLEView.h

#import <UIKit/UIKit.h> 

@interface BooksEAGLView : UIView{ 

    UIButton *save; 

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

@end 
0

BooksEAGLEView.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..."); 
} 
相关问题