【发布时间】:2012-08-25 22:20:53
【问题描述】:
我有一个 UIView 正在以编程方式创建:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
if (self) {
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
UIImageView* closeButton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"modal_close.png"]];
closeButton.frame = CGRectMake(self.frame.size.width*.89, self.frame.size.height*.09, closeButton.frame.size.width, closeButton.frame.size.height);
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width*.89, self.frame.size.height*.09,20, 20)];
[button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
UIView* mainView = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width*.1,self.frame.size.height*.1,self.frame.size.width*.8,self.frame.size.height*.8)];
mainView.backgroundColor = [UIColor whiteColor];
_displayMainView = mainView;
[self addSubview:_displayMainView];
[self addSubview:closeButton];
[self addSubview:button];
mainView = nil;
closeButton = nil;
}
return self;
}
如何检测旋转?这是作为另一个现有视图之上的模式。如果重要的话,这是一款仅限 iPad 的应用程序。
【问题讨论】:
-
你是指 UIVIew 的旋转角度,还是设备的方向?
-
查看这个出色的答案 - stackoverflow.com/a/3897243/194544
标签: objective-c ios uiview rotation