0

我正在创建一个应该支持横向和纵向的 iOS 应用程序。所以我为这两个方向使用了 2 个视图。但现在的问题是我不知道如何连接IBoutlets到文件的所有者。我们不能将一IBOutlet组用于两种模式。我还没有完成任何支持这两种模式的应用程序。请任何人都可以告诉我如何解决这个问题。

谢谢

4

1 回答 1

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;
    }

}

} `

于 2012-10-25T09:35:20.647 回答