ios 仿微信通讯录自定义侧栏sideView的滑动点击震动反馈效果

本文介绍了iOS开发中实现点击按钮及滑动时提供触觉反馈的方法。通过使用UIImpactFeedbackGenerator和UISelectionFeedbackGenerator,可以为用户提供更好的交互体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://ios.jobbole.com/92573/ 这个是百度到的

http://www.jianshu.com/p/630b644bf430这个是根据Api百度下的

写得很不错,找了好久才找到的,百度给的资源很少,希望对大家有用.

这个是单个点击的响应    

if (clickBtn.tag!=1) {

        UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];

        [generator prepare];

        [generator impactOccurred];

        NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:clickBtn.tag-1];

        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

        NSString * charStr = self.allIndexes[clickBtn.tag-1];

        [self showIndexTipLabel:charStr];


    }else{

        UIImpactFeedbackGenerator *generator = [[UIImpactFeedbackGenerator alloc] initWithStyle: UIImpactFeedbackStyleLight];

        [generator prepare];

        [generator impactOccurred];

        [self.tableView scrollRectToVisible:_searchBar.frame animated:NO];

    }


这个是滑动的响应

    CGPoint point = [pan translationInView:self.sidetableView];

    CGFloat orgin_y = point.y;

    NSInteger location = orgin_y/20;

    float locationF = orgin_y/20;

    if (location>0&&location<self.allIndexes.count) {

        NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:location];

        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

        NSString * charStr = self.allIndexes[location];

        [self showIndexTipLabel:charStr];

        

        UISelectionFeedbackGenerator *generator = [[UISelectionFeedbackGenerator alloc] init];

        switch (pan.state) {

            case UIGestureRecognizerStateBegan:

            {

                [generator prepare];

            }

                break;

            case UIGestureRecognizerStateChanged:

            {

                if ((locationF-location)<0.1) {

                    [generator selectionChanged];

                    [generator prepare];

                }


            }

                break;

            case UIGestureRecognizerStateCancelled:

            case UIGestureRecognizerStateEnded:

            case UIGestureRecognizerStateFailed:

            {

                generator = nil;

            }

                break;

            default:

                break;

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值