我正在为iPad做一个应用程序,我们在其中添加了两个用于Landscape的图像,另一个用于纵向模式,我已经编写了代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Return YES for supported orientations
if(interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self portraitFrames];
}
else {
[self landscapeFrames];
}
return YES;
}
- (void)landscapeFrames {
[customBackground setFrame:CGRectMake(0, 42.4, 1024, 725)];
[preparedForTextField setFrame:CGRectMake(435,140,300,30)];
[agentTextField setFrame:CGRectMake(435,205,300,30)];
[phoneTextField setFrame:CGRectMake(435,265,300,30)];
[dateTextField setFrame:CGRectMake(435,320,300,30)];
[customBackground setImage:backgroundImage];
}
- (void)portraitFrames {
[customBackground setFrame:CGRectMake(0, 42.4, 768, 913)];
[preparedForTextField setFrame:CGRectMake(312,220,300,30)];
[agentTextField setFrame:CGRectMake(312,280,300,30)];
[phoneTextField setFrame:CGRectMake(312,340,300,30)];
[dateTextField setFrame:CGRectMake(312,400,300,30)];
[customBackground setImage:backgroundImagePortrait];
}
ViewDidLoad中的
-(void)ViewDIdLoad{
// Some code related to textfields
UIInterfaceOrientation orientation =[[UIApplicationsharedApplication]statusBarOrientation];
if(orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
[self portraitFrames];
}
else {
[self landscapeFrames];
}
[self reloadTextFieldValues];
}
有人可以通过说是使用2种不同图像的正确方法帮助我,或者我们应该只使用1幅图像用于横向和纵向。如果是这样,我们怎样才能使用那些只有单张图像?我的应用程序因此而崩溃。请帮助我。
提前致谢。
微酸