I want to make an application that it capture all touch events and display x,y value in toolbar。
- If it's possible to capture all events although event not happened in this app ?
- How to show this开发者_开发百科 app in the Toolbar like the Battery icon (when app run in background) ?
1) You can capture touch events when your own app is running is pretty easy. One way would be to a single root view controller, implement
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
If you really are interested in displaying their coordinates, you will also have to think about questions like what happens in cases of multitouch.
However,
This is not possible for other apps. 2) is not possible at all. You don't have access to the status bar and you will not be able to do anything like capturing touch events when the application is in the background anyway. You can only capture events when your application is in the foreground.
Neither of your goals can be accomplished on a non-jailbroken device (and probably not even on a rooted one), because it violates the spirit of the Application Sandbox.
精彩评论