我是靠谱客的博主 敏感奇异果,这篇文章主要介绍鼠标移动UIview 位置随着鼠标改变,现在分享给大家,希望可以做个参考。

@interface TestView : UIView
@property(nonatomic,assign)CGPoint point;
@end




@interface TestView(){

    //开始触摸这个点
    CGPoint _startPoint;
    

}

@end





//当你开始触摸的时候,到这看看.
//一次出没时间发生时,该方法只执行一次.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    //取出手指触碰屏幕的坐标
    _startPoint =[[touches anyObject]locationInView:self];
   
    
    NSLog(@"我要开始摸了.");
    self.backgroundColor=[UIColor blueColor];

}
//一次触摸事件尚未结束,会一直调用该方法
//没摸完,就一直摸.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"触摸ing");
    self.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
    
    
    //取移动中的点
 
    CGPoint nowPoint=[[touches anyObject]locationInView:self];
    
    CGFloat x=nowPoint.x-_startPoint.x;
    CGFloat y=nowPoint.y - _startPoint.y;
    CGPoint centerPoint =CGPointMake(self.center.x+x,self.center.y+y );
    self.center =centerPoint;
}


//一次触摸事件结束,执行该方法
//摸完了
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"结束了");

}


//触摸事件被别的事件打算
//有人打扰
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{


}


最后

以上就是敏感奇异果最近收集整理的关于鼠标移动UIview 位置随着鼠标改变的全部内容,更多相关鼠标移动UIview内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部