在iOS 9上使用状态栏呈现视图控制器时,视图向下移动

时间:2016-05-10 17:14:27

标签: ios uiviewcontroller autolayout uistoryboard uistatusbar

我有一个视图控制器(view1),它更喜欢隐藏状态栏。我有一个按钮,从屏幕底部以模态方式显示另一个视图控制器(view2)(在我的故事板中显示' segue),view2更喜欢可见的状态栏。在iOS 8上,这是从view1到view2的平滑过渡,但在iOS 9上,当我按下按钮并且view1的整个视图向下移动以适应它时,状态栏立即出现在view1中。

这是一种难看的效果,我希望避免它。出于某种原因,iOS 8比iOS 9更优雅地处理它。有没有解决这个问题?

1 个答案:

答案 0 :(得分:0)

在Swift中,您可以在view2上将全局变量设置为

new ClientEngine(ip, port).execute(WindowsEventsEnum.MouseLeftButtonClick);

在view2的viewWillAppear上将其更改为true并更新状态栏

    public class ClientEngine extends AsyncTask<WindowsEventsEnum, Void, Void>{
    final String ip;
    final int port;
DatagramSocket socket;
    InetAddress remoteAdress;
    DatagramPacket sendingPacket;
    final String VOLUMEUP = "01";
    final String VOLUMEDOWN = "02";
    final String LMBCLICK = "11";
    final String RMBCLICK = "12";
    final String MMBUP = "21";
    final String MMBDOWN = "22";
    final String ENDCONNECTION = "ec";


    public ClientEngine(String ip, int port) throws SocketException, UnknownHostException {
        this.ip = ip;
        this.port = port;
        socket = new DatagramSocket();
        remoteAdress = InetAddress.getByName(ip);
    }

    public void OpenConnection() throws IOException {


    }

    public void CloseConnection() throws IOException {

socket.close();
    }

    public void MouseLeftButtonClick() throws IOException {
byte[] sendDatagram = LMBCLICK.getBytes();
        sendingPacket = new DatagramPacket(sendDatagram, sendDatagram.length, remoteAdress, port);
        socket.send(sendingPacket);
    }

    public void MouseRightButtonClick() throws IOException {
        byte[] sendDatagram = RMBCLICK.getBytes();
        sendingPacket = new DatagramPacket(sendDatagram, sendDatagram.length, remoteAdress, port);
        socket.send(sendingPacket);
    }

    public void SystemVolumeUp() throws IOException {

    }

    public void SystemVolumeDown() throws IOException {

    }

    @Override
    protected Void doInBackground(WindowsEventsEnum... params) {
        switch (params[0]) {
            case MouseLeftButtonClick:
                try {
                    MouseLeftButtonClick();
                    CloseConnection();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case MouseRightButtonClick:
                try {
                    MouseRightButtonClick();
                    CloseConnection();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
       return null;
    }

}

状态栏委托功能看起来像

isStatusBarHidden = false

这只适用于Swift,而非Objective-C。