iOS小技能:获取屏幕坐标的方式

475 阅读2分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第6天,点击查看活动详情

前言

获取屏幕坐标的方式:

  1. LUA 函数touchDown(idx, x, y) 获取坐标

x,y 整数型 屏幕坐标

屏幕坐标,横坐标为 x,纵坐标为 y,单位为像素。

例如,iPhone 4 与 iPhone 4S 的屏幕分辨率 为 640 * 960,则其最大横坐标为 640,最大纵坐标为 960。

lua脚本常常作为触动精灵的代码,而进行辅助完成功能。

  1. 使用iOS API获取在屏幕上的点击坐标
  2. 先截图,然后用photoshop打开,用PS 去描点获取。

I 使用catchTouchPoint 函数实现点坐标的获取

获取用户点击的坐标


		--test
--获取用户点击的坐标 
         -- x,y = catchTouchPoint();

		-- sysLog("tcatchTouchPoint"..x..","..y);



		--end test
  • 结果日志
 * PID 2751
Oct 15 10:45:27 iPhone iCal135c[2751] <Warning>: tcatchTouchPoint367,732
Oct 15 10:45:57 iPhone iCal135c[2751] <Warning>: tcatchTouchPoint269,1112
Oct 15 10:48:26 iPhone iCal135c[2751] <Warning>: tcatchTouchPoint365,769
Oct 15 10:48:35 iPhone iCal135c[2751] <Warning>: tcatchTouchPoint459,565
Oct 15 10:53:29 iPhone iCal135c[2751] <Warning>: tcatchTouchPoint405,722
exit

II 使用iOS API获取在屏幕上的点击坐标

private demo

download.csdn.net/download/u0…

2.1 创建UIApplication 子类,实现sendEvent:获取在屏幕上的点击坐标

//获取在屏幕上的点击坐标

- (void)sendEvent:(UIEvent *)event{
    if (event.type==UIEventTypeTouches) {
        UITouch *touch = [event.allTouches anyObject];
        
        if (touch.phase == UITouchPhaseBegan) {
            self.isMoved = NO;
        }
        
//        if (touch.phase == UITouchPhaseMoved) {//滑动
//            self.isMoved = YES;
//        }
        
        if (touch.phase == UITouchPhaseEnded) {
            
            
            if (!self.isMoved && event.allTouches.count == 1) {//非多点触控,非滑动
                
                
                UITouch *touch = [event.allTouches anyObject];
                
                //在屏幕上的点击坐标
                CGPoint locationPointWindow = [touch preciseLocationInView:touch.window];//touch.view
                
                
                
                NSLog(@"TouchLocationWindow:(%.1f,%.1f)",locationPointWindow.x,locationPointWindow.y);
                
                
            }
            self.isMoved = NO;
        }
    }
    [super sendEvent:event];
}


2.2 在main方法添加principalClassName

int main(int argc, char * argv[]) {
    NSString * appDelegateClassName;
    
    NSString * principalClassName;// The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.


    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
        
        principalClassName =   NSStringFromClass([KNApplication4sendEvent class]);
        
        
        
        
        
        
    }
    

    return UIApplicationMain(argc, argv, principalClassName, appDelegateClassName);
    
    
}

see also

【lua 函数】 获取用户点击的坐标、获取操作系统的版本号、 读取粘贴板、写入粘贴板blog.csdn.net/z929118967/…

gzh:iOS逆向