iOS13:如何检测状态栏的单击事件?

时间:2019-08-02 10:03:36

标签: objective-c ios13

在我的appDelegate中,我覆盖touchesBegan来检测何时单击状态栏:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];

    CGPoint location = [[[event allTouches] anyObject] locationInView:kWindow];
    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;

    if (CGRectContainsPoint(statusBarFrame, location)) {
        ///do something 
    }
}

在iOS 13之前,此功能有效;在iOS 13上则没有。该方法从不执行。我该如何解决?

2 个答案:

答案 0 :(得分:3)

经过研究,我发现状态栏不再是iOS13上应用程序的一部分,而是系统UI(“跳板”)的一部分。您需要通过UIStatusBarManager

进行访问

所以这不再起作用:

from collections import deque
class Solution:

    def solve(self, A, B, C, D, board):
        # @param A, B: (x, y) co-ordinates of start position
        # @param C, D: (x, y) co-ordinates of target position
        # @param board : list of strings
        # @return minimum moves required or impossible

        seen = set()

        def neighbors(i, j):
            @param i, j: co-ordinates of current position
            @return list with all possible valid moves

            nei = []
            x, y = i - 1, j
            while x >= 0 and board[x][y] != '1':
                nei.append((x, y))
                x -= 1

            x, y = i + 1, j
            while x < len(board) and board[x][y] != '1':
                nei.append((x, y))
                x += 1

            x, y = i, j - 1
            while y >= 0 and board[x][y] != '1':
                nei.append((x, y))
                y -= 1

            x, y = i, j + 1
            while y < len(board[0]) and board[x][y] != '1':
                nei.append((x, y))
                y += 1

            return nei

        def bfs(i, j):
            que = deque([(i, j, 0)])

            while que:
                m, n, level = que.popleft()
                seen.add((m, n))

                if m == C and n == D:
                    return level

                for x, y in neighbors(m, n):
                    if (x, y) not in seen:
                        que.append((x, y, level + 1))
                        seen.add((x, y))

            return -1

        return bfs(A, B)

在iOS 13中,您需要像下面这样获取StatusBar框架:

CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;

答案 1 :(得分:1)

在iOS 13中,StatusBar事件由UIStatusBarManager管理,当单击StatusBar时将调用以下方法:

-[UIStatusBarManager _handleScrollToTopAtXPosition:]
-[UIStatusBarManager handleTapAction:]

因此,您可以钩住-[UIStatusBarManager handleTapAction:]来检测StatusBar点击事件