У меня очень проблематичная проблема. У меня есть UIView
с несколькими кнопками, расположенными на нем. По какой-либо причине, когда вы поворачиваете представление (симулятор или устройство), кнопки в правой половине экрана становятся незаметными. Неприкасаемая область напоминает размер ориентации, с которой только что повернулся. Например, если у вас есть iPhone в портретном режиме и превратите его в пейзаж, то незащищенная область будет равна ширине экрана iPhone в портрете. Сначала я думал, что они должны быть невидимым элементом поверх той части экрана, которая перехватывала клики, но затем я установил альфа всего экрана на 1 и установил каждый цвет границы элементов (через CALayer
), чтобы я мог осмотреть. Удивительно, но все было там, где должно было быть, и их было ничего (что я мог найти), закрывая кнопки. Я даже попытался привнести кнопки на передний край через [self.view bringSubviewToFront:self.BUTTON]
Половина экрана unclickable
У меня есть одна функция, которая обрабатывает рамки всего, когда вид загружается или поворачивается. Этот вызов функции является ТОЛЬКО в моей функции вращения и моей функцией viewWillAppear
. Проблема с незаменимыми кнопками возникает только при повороте устройства. Например, если вы поворачиваете устройство из портрета в альбомное, а кнопки становятся незаметными, то все, что вам нужно сделать, это выбрать другую вкладку на панели вкладок внизу, чтобы загрузить другое представление, а затем, когда вы нажимаете на вкладку с помощью просмотрите эту странную проблему (не поворачивая ничего), все кнопки доступны и работают как ожидалось. Вещь, которую я просто не могу понять об этой проблеме, заключается в том, что ТОЧНЫЙ же код вызывается в viewWillAppear
и didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
, но кнопки не отключаются, когда устройство повернуто и кнопки нажимаются. Если пользователь нажимает на другую вкладку, а затем возвращает вкладку с этой проблемой, кнопки теперь работают так, как ожидалось.
Чтобы усложнить ситуацию, эта проблема ТОЛЬКО возникает на ios7. Все в порядке и денди на ios6.
Я пробовал все, о чем я могу думать, и у меня просто нет подсказки, почему это происходит.
Вот некоторые из кода:
-(void)loadCorrectElements{
if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
//portrait
int amountToSubtract = ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?20:0;
int distanceBetweenLabels = (self.view.bounds.size.height - amountToSubtract)/5;
self.viewForLabels.frame = CGRectMake(0, distanceBetweenLabels, self.view.bounds.size.width, distanceBetweenLabels*3);
int heightOfLabels = (self.viewForLabels.bounds.size.height/3) - 20;
int ycoordOfLongitudeLabel = (self.viewForLabels.bounds.size.height/3) + 10;
int ycoordOfAltitudeLabel = ((self.viewForLabels.bounds.size.height/3) * 2) + 10;
self.latitudeLabel.frame = CGRectMake(10, 10, self.view.bounds.size.width-20, heightOfLabels);
self.longitudeLabel.frame = CGRectMake(10, ycoordOfLongitudeLabel, self.view.bounds.size.width-20, heightOfLabels);
self.altitudeLabel.frame = CGRectMake(10, ycoordOfAltitudeLabel, self.view.bounds.size.width-20, heightOfLabels);
self.optionsButton.frame = CGRectMake(self.view.bounds.size.width-36, self.view.bounds.size.height-36, 26, 26);
int ycoordForSpeakButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + 10;
self.speakButton.frame = CGRectMake(self.view.bounds.size.width - 40, ycoordForSpeakButton, 30, 25);
int heightOfRecordLabel = ((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height)))/2;
int yCoordForRecordButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + (((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height))/2) - (heightOfRecordLabel/2));
self.recordButton.frame = CGRectMake((self.view.bounds.size.width/2) - (self.view.bounds.size.width/4)/2, yCoordForRecordButton, self.view.bounds.size.width/4, heightOfRecordLabel);
int ycoordForOldCoordsButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + (((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height)))/2 - 12);
self.oldCoordsButton.frame = CGRectMake(10, ycoordForOldCoordsButton, 24, 24);
}else{
//landscape
int amountToSubtract = ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?20:0;
self.viewForLabels.frame = CGRectMake(5, 5 + amountToSubtract, self.view.bounds.size.width-10, self.view.bounds.size.height - 60);
int heightOfLabels = (self.viewForLabels.bounds.size.height - amountToSubtract)/3;
int ycoordOfLongitudeLabel = (self.viewForLabels.bounds.size.height/3);
int ycoordOfAltitudeLabel = ((self.viewForLabels.bounds.size.height/3) * 2);
self.latitudeLabel.frame = CGRectMake(5, 0, self.view.bounds.size.width-20, heightOfLabels);
self.longitudeLabel.frame = CGRectMake(5, ycoordOfLongitudeLabel, self.view.bounds.size.width-20, heightOfLabels);
self.altitudeLabel.frame = CGRectMake(5, ycoordOfAltitudeLabel, self.view.bounds.size.width-20, heightOfLabels);
int yCoordForOptionsButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + (((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height))/2) - 13);
self.optionsButton.frame = CGRectMake(self.view.bounds.size.width - 31, yCoordForOptionsButton, 26, 26);
self.speakButton.frame = CGRectMake(self.optionsButton.frame.origin.x - 40, self.optionsButton.frame.origin.y, 30, 25);
int heightOfRecordLabel = ((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height)))/2;
int yCoordForRecordButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + (((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height))/2) - (heightOfRecordLabel/2));
self.recordButton.frame = CGRectMake((self.view.bounds.size.width/2) - (self.view.bounds.size.width/4)/2, yCoordForRecordButton, self.view.bounds.size.width/4, heightOfRecordLabel);
int ycoordForOldCoordsButton = self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height + (((self.view.bounds.size.height - (self.viewForLabels.frame.origin.y + self.viewForLabels.frame.size.height)))/2 - 12);
self.oldCoordsButton.frame = CGRectMake(10, ycoordForOldCoordsButton, 24, 24);
}//end if
[self setLabelText:self.latitudeLabel text:self.latitudeLabel.text];
[self setLabelText:self.longitudeLabel text:self.longitudeLabel.text];
[self setLabelText:self.altitudeLabel text:self.altitudeLabel.text];
self.mainContainer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}//end method
-(void)viewWillAppear:(BOOL)animated{
[self loadCorrectElements];
}//end function
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self loadCorrectElements];
}//end function
Вот заявление кнопки внутри ViewDidLoad
//create options button
self.optionsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.optionsButton setImage:[UIImage imageNamed:@"Share.png"] forState:UIControlStateNormal];
[self.optionsButton addTarget:self action:@selector(shareButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.mainContainer addSubview:self.optionsButton];
//create speak button
self.speakButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.speakButton setImage:[UIImage imageNamed:@"Sound.png"] forState:UIControlStateNormal];
[self.speakButton addTarget:self action:@selector(speakButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.mainContainer addSubview:self.speakButton];
//create record button
self.recordButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.recordButton.backgroundColor = self.blueColor;
[self.recordButton setTitle:NSLocalizedString(@"RECORD", nil) forState:UIControlStateNormal];
self.recordButton.layer.cornerRadius = 3.0f;
[self.recordButton addTarget:self action:@selector(recordButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.recordButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[self.mainContainer addSubview:self.recordButton];
//set up old coord button
self.oldCoordsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.oldCoordsButton setImage:[UIImage imageNamed:@"Clock.png"] forState:UIControlStateNormal];
[self.oldCoordsButton addTarget:self action:@selector(oldCoordsButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.mainContainer addSubview:self.oldCoordsButton];