我有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];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 {
}
}
}发布于 2014-06-09 17:53:39
将以下代码放入您调用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-09 20:29:19
请参考此代码
#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-09 20:32:27
BooksEAGLEView.h
#import <UIKit/UIKit.h>
@interface BooksEAGLView : UIView{
UIButton *save;
}
@property(nonatomic, retain) UIButton *save;
@endhttps://stackoverflow.com/questions/24116578
复制相似问题