Tôi có một UIView
đó là lập trình được tạo ra:Làm thế nào để phát hiện luân phiên cho một UIView tạo theo chương trình
- (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;
}
Làm thế nào tôi có thể phát hiện luân chuyển? Điều này là để hoạt động như một phương thức trên một chế độ xem hiện tại khác. Đây là một ứng dụng chỉ dành cho iPad, nếu điều đó quan trọng.
Bạn có nghĩa là góc UIView của luân chuyển, hoặc định hướng của thiết bị? –
Xem câu trả lời tuyệt vời này - http://stackoverflow.com/a/3897243/194544 – beryllium