【发布时间】:2010-08-27 19:29:20
【问题描述】:
好的,我有一个非常基本的应用程序,其中包含一个按钮的视图。我将控制器设置为仅允许横向。我的问题是,在它初始化之后,然后我点击我的按钮(它只有一个日志语句),与我在初始化结束时的日志语句不同。
我在模拟器上以横向模式启动应用程序(但在设备上的结果相同)。就像一旦我分配它,它就会切换回来。我在我的 buttonClicked 方法中尝试了这个声明 self.frame = CGRectMake(0, 0, 1024, 768);,但这只是扭曲并改变了它。
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
//BUTTONS
attributesButton = [UIButton buttonWithType:UIButtonTypeCustom];
attributesButton.frame = CGRectMake(self.frame.size.width - buttonPadding - 35, self.frame.size.height/2 -22 -150, 35, 35);
[attributesButton setBackgroundImage:[UIImage imageNamed:@"loadIcon.png"] forState:UIControlStateNormal];
[attributesButton addTarget:self action:@selector(attributesButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[attributesButton setTitle:@"Attr" forState:UIControlStateNormal];
[self addSubview:attributesButton];
NSLog(@"Width: %f",self.frame.size.width);
NSLog(@"Height: %f",self.frame.size.height);
}
return self;
}
-(void)attributesButtonClicked
{
NSLog(@"Width: %f",self.frame.size.width);
NSLog(@"Height: %f",self.frame.size.height);
}
这就是我的初始化。抱歉,它看起来很糟糕,我不知道为什么。我的视图控制器:
- (void)loadView
{
NSLog(@"myViewController: loadView");
myView = [[myView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
self.view = myView;
}
现在这是让我感兴趣的部分,日志语句。
2010-08-27 15:16:55.242 tester[8703:40b] myViewController: loadView
2010-08-27 15:16:55.262 tester[8703:40b] Width: 1024.000000
2010-08-27 15:16:55.262 tester[8703:40b] Height: 768.000000
CLICK MY BUTTON HERE
2010-08-27 15:17:05.689 tester[8703:40b] Width: 748.000000
2010-08-27 15:17:05.689 tester[8703:40b] Height: 1024.000000
【问题讨论】:
标签: iphone ipad uiview size frame