这是iPad应用程序。我想在设备更改方向时自动关闭选择器视图。键盘关闭完成了方向屏幕更改。键盘被关闭且方向已更改但方向视图大小向下移动意味着多次调用动画功能我该如何解决此问题< / p>
我希望定位屏幕保持不变 以下是我的代码: -
-(void)receivedRotate:(NSNotification *)notification{
[self checkOrientation];
}
-(void)checkOrientation{
UIInterfaceOrientation orientation = self.interfaceOrientation;
@try{
if([txtViewComponents isFirstResponder])
[self done];
if([txtIntervalFrequency isFirstResponder])
[self toolbarDayBtn];
if([textRepeated isFirstResponder])
[self toolbarbtn];
if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
{
float xAxisLeftLbl=50;
float xAxisLeftTxt=250;
float txtWidth=230;
float txtHeight=35;
float lblHeight=35;
float height=100;
CGRect rect = CGRectMake(xAxisLeftLbl, 60, 144, lblHeight);
lblFacility.frame = rect;
rect = CGRectMake(xAxisLeftTxt, 60, txtWidth, txtHeight);
txtFacility.frame = rect;
rect = CGRectMake(xAxisLeftLbl,self.lblFacility.frame.origin.y+height , 239, lblHeight);
lblActivityTypes.frame = rect;
rect = CGRectMake(xAxisLeftTxt,txtFacility.frame.origin.y+height , txtWidth, txtHeight);
txtActivityTypes.frame = rect;
rect = CGRectMake(xAxisLeftLbl, txtActivityTypes.frame.origin.y+height, 157, lblHeight);
lblComponents.frame = rect;
rect = CGRectMake(xAxisLeftTxt,txtActivityTypes .frame.origin.y+height, txtWidth, 130);
txtViewComponents.frame = rect;
rect = CGRectMake(xAxisLeftLbl, lblComponents.frame.origin.y+ txtViewComponents.frame.size.height+height-30, 239, lblHeight);
lblDescription.frame = rect;
rect = CGRectMake(xAxisLeftTxt,txtViewComponents.frame.origin.y+txtViewComponents.frame.size.height+height-30, txtWidth, 130);
txtViewDescription.frame = rect;
float xAxisRightLbl=500;
float xAxisRightTxt=750;
rect = CGRectMake(xAxisRightLbl, 60, 241, lblHeight);
lblResponsible.frame = rect;
rect = CGRectMake(xAxisRightTxt, 60, txtWidth, txtHeight);
txtResponsible.frame = rect;
rect = CGRectMake(xAxisRightLbl, txtResponsible .frame.origin.y+height,157, lblHeight);
lblStartDate.frame = rect;
rect = CGRectMake(xAxisRightTxt, txtResponsible .frame.origin.y+height, txtWidth, txtHeight);
txtStartDate.frame = rect;
rect = CGRectMake(xAxisRightLbl, txtStartDate .frame.origin.y+height, 239, lblHeight);
lblReactivateDeactivate.frame = rect;
rect = CGRectMake(xAxisRightTxt, txtStartDate.frame.origin.y+height, txtWidth, txtHeight);
swicthReactivateDeactivate.frame = rect;
rect = CGRectMake(xAxisRightLbl, lblReactivateDeactivate.frame.origin.y+height, 239, lblHeight);
lblIntervalFrequency.frame = rect;
rect = CGRectMake(xAxisRightTxt, swicthReactivateDeactivate.frame.origin.y+height, 55, txtHeight);
lblevery.frame = rect;
rect = CGRectMake(xAxisRightTxt+lblevery.frame.size.width+10, swicthReactivateDeactivate.frame.origin.y+height, 65, txtHeight);
textRepeated.frame = rect;
rect = CGRectMake(xAxisRightTxt+textRepeated.frame.size.width+lblevery.frame.size.width+20, swicthReactivateDeactivate.frame.origin.y+height, 94, txtHeight);
txtIntervalFrequency.frame = rect;
rect = CGRectMake(xAxisRightLbl,lblIntervalFrequency.frame.origin.y+height, 200, lblHeight);
lblDeadline.frame = rect;
rect = CGRectMake(xAxisRightTxt,txtIntervalFrequency.frame.origin.y+height, txtWidth, txtHeight);
txtDeadline.frame = rect;
rect = CGRectMake(0,txtDeadline.frame.origin.y+185, self.view.frame.size.width+300
, 60);
bottomImage.frame = rect;
rect = CGRectMake(420,txtDeadline.frame.origin.y+200,200,35);
btnCreateNewActivity.frame = rect;
}else{
float xAxisLbl=100;
float xAxisTxt=450;
float txtWidth=250;
float txtHeight=35;
float lblHeight=35;
float yxis=74;
CGRect rect = CGRectMake(xAxisLbl, 40, 144, lblHeight);
lblFacility.frame = rect;
rect = CGRectMake(xAxisTxt, 40, txtWidth, txtHeight);
txtFacility .frame = rect;
rect = CGRectMake(xAxisLbl,lblFacility.frame.origin.y+yxis , 239, lblHeight);
lblActivityTypes.frame = rect;
rect = CGRectMake(xAxisTxt,txtFacility.frame.origin.y+yxis, txtWidth, txtHeight);
txtActivityTypes.frame = rect;
rect = CGRectMake(xAxisLbl, txtActivityTypes.frame.origin.y+yxis, 157, lblHeight);
lblComponents.frame = rect;
rect = CGRectMake(xAxisTxt,txtActivityTypes .frame.origin.y+yxis, txtWidth,130);
txtViewComponents.frame = rect;
rect = CGRectMake(xAxisLbl,txtViewComponents.frame.size.height+txtViewComponents.frame.origin.y+yxis-30 ,239, lblHeight);
lblDescription.frame = rect;
rect = CGRectMake(xAxisTxt,txtViewComponents.frame.size.height+yxis+txtViewComponents.frame.origin.y-30, txtWidth, 130);
txtViewDescription.frame = rect;
rect = CGRectMake(xAxisLbl, lblDescription.frame.origin.y+yxis+txtViewDescription.frame.size.height-30, 241, lblHeight);
lblResponsible.frame = rect;
rect = CGRectMake(xAxisTxt,txtViewDescription.frame.origin.y+yxis+txtViewDescription.frame.size.height-30, txtWidth, txtHeight);
txtResponsible.frame = rect;
rect = CGRectMake(xAxisLbl, txtResponsible .frame.origin.y+yxis,157, lblHeight);
lblStartDate.frame = rect;
rect = CGRectMake(xAxisTxt, txtResponsible .frame.origin.y+yxis, txtWidth, txtHeight);
txtStartDate.frame = rect;
rect = CGRectMake(xAxisLbl, txtStartDate .frame.origin.y+yxis, 239, lblHeight);
lblReactivateDeactivate.frame = rect;
rect = CGRectMake(xAxisTxt, txtStartDate.frame.origin.y+yxis, txtWidth, txtHeight);
swicthReactivateDeactivate.frame = rect;
rect = CGRectMake(xAxisLbl, lblReactivateDeactivate.frame.origin.y+yxis, 239, lblHeight);
lblIntervalFrequency.frame = rect;
rect = CGRectMake(xAxisTxt, swicthReactivateDeactivate.frame.origin.y+yxis, 55, txtHeight);
lblevery.frame = rect;
rect = CGRectMake(xAxisTxt+lblevery.frame.size.width+10, swicthReactivateDeactivate.frame.origin.y+yxis, 70, txtHeight);
textRepeated.frame = rect;
rect = CGRectMake(xAxisTxt+lblevery.frame.size.width+20+textRepeated.frame.size.width, swicthReactivateDeactivate.frame.origin.y+yxis, 100, txtHeight);
txtIntervalFrequency.frame = rect;
rect = CGRectMake(xAxisLbl, lblIntervalFrequency.frame.origin.y+yxis, txtWidth, lblHeight);
lblDeadline.frame = rect;
rect = CGRectMake(xAxisTxt,txtIntervalFrequency.frame.origin.y+yxis, txtWidth, txtHeight);
txtDeadline.frame = rect;
rect = CGRectMake(0,txtDeadline.frame.origin.y+yxis, self.view.frame.size.width+300
, 60);
bottomImage.frame = rect;
rect = CGRectMake(280,txtDeadline.frame.origin.y+yxis+10,250,35);
btnCreateNewActivity.frame = rect;
}
NSLog(@"keyboardShown : %i", keyboardShown);
}
@catch (NSException *ex) {
[Utils LogExceptionOnServer:@"CreateActivityViewController" methodName:@"receivedRotate" exception:[ex description]];
}
}
-(void)keyboardWillShow:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo]; // user info dictionary object
// to get the keyborad size
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
if(txtfield != nil)//textfiled set globel value and put the value
{
if (txtfield.frame.origin.y>self.view.frame.size.height- kbSize.height)
{
raiseHeight = kbSize.height - txtfield.frame.size.height;//set the raiseaHeight vale here when its
[self setViewMovedUp:YES];
keyboardShown = YES;
}
}
else if(txtViewActive != nil )
{
if(txtViewActive.frame.origin.y>self.view.frame.size.height- kbSize.height)
{
raiseHeight = kbSize.height - txtViewActive.frame.size.height;
[self setViewMovedUp:YES];
keyboardShown = YES;
}
}
}
-(void)keyboardWillHide:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
if(txtfield != nil || keyboardShown)
{
if (txtfield.frame.origin.y>self.view.frame.size.height- kbSize.height || keyboardShown)
{
[self setViewMovedUp:NO];
keyboardShown = NO;
}
}
else if(txtViewActive != nil || keyboardShown)
{
if(txtViewActive.frame.origin.y>self.view.frame.size.height- kbSize.height || keyboardShown)
{
[self setViewMovedUp:NO];
keyboardShown = NO;
}
}
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:
)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
- (IBAction)toolbarbtn{
toolbarmonth.hidden=YES;
toolbarDay.hidden=YES;
[textRepeated setText:[currentArray objectAtIndex:selectedRow]];
[textRepeated resignFirstResponder];
}
- (IBAction)toolbarDayBtn{
toolbarmonth.hidden=YES;
toolbarDay.hidden=YES;
[txtIntervalFrequency setText:[currentArray objectAtIndex:selectedRow]];
[txtIntervalFrequency resignFirstResponder];
}