XCode:调整图像使用宽高比并向下移动图像下方的元素

时间:2017-09-21 08:47:47

标签: ios xcode uiview xamarin.ios uiimageview

当用户在iPad上更改方向时,我坚持使用调整大小图像。

我想在横向上调整图像大小(宽高比),然后向下移动该图像下方的所有行(视图)。

现在当旋转屏幕图像非常拉伸时。

旋转屏幕时如何进行负责任的设计?

What I have in Portrait mode What I want to get in Landscape mode

对不起,我是Xcode的新手。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在Xcode中使用委托viewWillTransitionToSize:withTransitionCoordinator:,或在Xamarin.iOS中使用ViewWillTransitionToSize在旋转屏幕时调整视图大小。

Xcode中使用Objective-C的示例代码:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    // Code here will execute before the rotation begins.
    // Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:].
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        // Place code here to perform animations during the rotation.
        // You can pass nil for this closure if not necessary.
        // Reorganize views, or move child view controllers.
        if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {

            //Update UI
        }

        if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {

            //Update UI
        }

    }completion:^(id<UIViewControllerTransitionCoordinatorContext> context){
                                     // Code here will execute after the rotation has finished.
                                     // Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:].
                                     // Do any cleanup, if necessary.

                                 }];
}

Xamarin.iOS中使用C#的示例代码:

    public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
    {
        base.ViewWillTransitionToSize(toSize, coordinator);

        coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext) => {

            if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)
            {
                //Update UI
            }

            if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft|| UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
            {
                //Update UI
            }

        }, (IUIViewControllerTransitionCoordinatorContext) => {
            //Transition Completion
        });
    }