iOS AssistiveTouch效果

1.
ex_one.gif

2.添加在當(dāng)前控制器頁面上 只在當(dāng)前VC的view中顯示可左右上下滑動 全局的話加在window上 直接上代碼
- (UIButton *)factBtn{
    if (!_factBtn) {
        _factBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _factBtn.frame = CGRectMake(kSWidth-65, 0.7*kSHeight, 40,40);
        [_factBtn setImage:[UIImage imageNamed:@"baoliao"] forState:UIControlStateNormal];
        [_factBtn addTarget:self action:@selector(factBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]
                                                        initWithTarget:self
                                                        action:@selector(handlePan:)];
        
        [_factBtn addGestureRecognizer:panGestureRecognizer];
    }
    return _factBtn;
}


- (void) handlePan:(UIPanGestureRecognizer*) recognizer

{
    
    CGPoint translation = [recognizer translationInView:self.view];
    CGFloat centerX=recognizer.view.center.x+ translation.x;
    CGFloat thecenter=0;
    recognizer.view.center=CGPointMake(centerX,
                                       recognizer.view.center.y+ translation.y);
    [recognizer setTranslation:CGPointZero inView:self.view];
    if(recognizer.state==UIGestureRecognizerStateEnded|| recognizer.state==UIGestureRecognizerStateCancelled) {
        if(centerX>kSWidth/2) {
            thecenter=kSWidth-40/2;
        }else{
            thecenter=40/2;
        }
             // contentOff_Y button允許拖動的Y值 根據(jù)需求調(diào)整(button沒有Y值限制時刪除下面兩個判斷即可) 
            //  Height_TabBar: tabbar高度  Height_NavBar: navbar 高度
        CGFloat contentOff_Y = recognizer.view.center.y;
        if (contentOff_Y > kSHeight-Height_TabBar-40) {
            contentOff_Y = kSHeight-Height_TabBar-20;
        }
        if (contentOff_Y < Height_NavBar) {
            contentOff_Y = Height_NavBar+20;
        }
        
        [UIView animateWithDuration:0.3 animations:^{
            recognizer.view.center=CGPointMake(thecenter,
                                               contentOff_Y+ translation.y);
            
        }];
    }
}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容