我正在创建一个应该支持横向和纵向的iOS应用程序。所以我对这两个方向使用了2个视图。但现在问题是我不知道如何将IBoutlets
连接到文件的所有者。我们不能对这两种模式使用一个IBOutlet
集。我没有做任何支持这两种模式的应用程序。请任何人告诉我如何解决这个问题。
由于
答案 0 :(得分:0)
最后我按照这种方式找到了这个。我创建了2个视图并定义了单独的IBOutlets集。更改方向时,我将一种模式下的值分配给其他模式的插座值。这是在(void)didRotate:(NSNotification *)notification
`
-(void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
if (newOrientation != UIDeviceOrientationUnknown && newOrientation != UIDeviceOrientationFaceUp && newOrientation != UIDeviceOrientationFaceDown)
{
if (orientation != newOrientation)
{
//ORIENTATION HAS CHANGED
NSLog(@"Changed Orientation");
// Do orientation logic
if (
((newOrientation == UIDeviceOrientationLandscapeLeft || newOrientation == UIDeviceOrientationLandscapeRight)) &&
((orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown))
)
{
NSLog(@"Changed Orientation To Landscape");
self.orientationMode=@"landscape";
self.txtInsidernameLandscape.text=self.txtInsiderName.text;
self.txtCompanynameLandscape.text=self.txtCompanyName.text;
self.txtAddressLandscape.text=self.txtAddress.text;
self.txtPhoneLandscape.text=self.txtTelephone.text;
self.txtEmailLandscape.text=self.txtEmail.text;
// Clear the current view and insert the orientation specific view.
[self clearCurrentView];
[self.view insertSubview:mainLandscapeView atIndex:0];
//Copy object states between views
//SomeTextControlL.text = SomeTextControlP.text;
}
else if (
((newOrientation == UIDeviceOrientationPortrait || newOrientation == UIDeviceOrientationPortraitUpsideDown)) &&
((orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight))
)
{
NSLog(@"Changed Orientation To Portrait");
self.orientationMode=@"portrait";
self.txtInsiderName.text=self.txtInsidernameLandscape.text;
self.txtCompanyName.text=self.txtCompanynameLandscape.text;
self.txtAddress.text=self.txtAddressLandscape.text;
self.txtPhoneLandscape.text=self.txtPhoneLandscape.text;
self.txtEmail.text=self.txtEmailLandscape.text;
// Clear the current view and insert the orientation specific view.
[self clearCurrentView];
[self.view insertSubview:mainPortraitView atIndex:0];
//Copy object states between views
//SomeTextControlP.text = SomeTextControlL.text;
}
orientation = newOrientation;
}
}
} `