您好,登錄后才能下訂單哦!
#pragma?mark?在UIView視圖結構中查找點擊view的觸摸事件 -?(UIView?*)hitTest:(CGPoint)point?withEvent:(UIEvent?*)event{ ???? ????//?如果不可以交互?|?隱藏?|?透明度太小?3者任意一個都忽略不能點擊 ????if(!self.userInteractionEnabled?||?self.hidden?||?self.alpha<=0.01){ ????????return?nil; ????} ????if([self?pointInside:point?withEvent:event]){ ???????? ???????__block?UIView?*hit?=??nil; ???????? ????????//NSEnumerationReverse?倒序 ????????[self.subviews?enumerateObjectsWithOptions:(NSEnumerationReverse)?usingBlock:^(__kindof?UIView?*?_Nonnull?obj,?NSUInteger?idx,?BOOL?*?_Nonnull?stop)?{ ???????????? ????????????///進行坐標轉化 ????????????CGPoint?vonverPoint?=?[self?convertPoint:point?toView:obj]; ????????????hit?=?[obj?hitTest:vonverPoint?withEvent:event]; ????????????if(hit){ ????????????????*stop?=?YES; ????????????} ????????}]; ????????if(hit){ ????????????return?hit; ????????}else{ ????????????return?self; ????????} ????}else{ ????????return?nil; ????} } #pragma?mark?觸摸的位置是否在當前view視圖中合適的點擊位置 -?(BOOL)pointInside:(CGPoint)point?withEvent:(UIEvent?*)event{ ???? ????CGFloat?x1?=?point.x;?//?觸摸的x ????CGFloat?y1?=?point.y;?//?觸摸的y ???? ????CGFloat?x2?=?self.frame.size.width/2;?//view的?x ????CGFloat?y2?=?self.frame.size.height/2;?//view的?y ???? ???? ????double?dis?=?sqrt((x1-x2?)*(x1-x2)?+?(y1-y2?)*(y1-y2));?//這里設置自己的判斷,button的大小?或者按鈕中心的一點?或者buton里放置的最大圓等 ????if(dis<=self.frame.size.width/2){?//判斷當前觸摸的點是不是自己要點擊的區域 ????????return?YES; ????}else{ ????????return?NO; ????} }
在UIView中做的轉盤游戲,我們需要判斷點擊的位置,然后做對應的點擊事件處理,我們就可以用上面的辦法,或者tabBar凸出的部分等都會用到,首先就要了解hitTest是什么,然后他的調用順序才能合理的應用,來極大的縮短時間。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。