moveshow-监听手指位置趣味小程序

本文介绍了一种在iOS应用中实现滑动特效的方法,当手指滑过特定图标时,图标会展示不同的视觉效果,例如更换背景图片。通过监听触摸事件并在不同状态下更改图标样式来达到这一效果。

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

突发奇想想要在公司的应用上添加一个原本在网页上的效果,就是手指滑动到某一个图标上,没有点击就会显示一个效果,可能是一段文字,或者是图标的特效展示。具体的就像是mac系统下方那个导航一样,随着手指的滑动而变大缩小。

很简单的应用,也没花几分钟时间,但是觉得很有意思
可能对于新手来说,可以顺便看看touch捕捉事件函数
moveshow-监听手指位置趣味小程序 - 柠檬加冰 - 柠檬加冰的博客
 
应该是不需要上传源代码的。。关键代码就几行

@interface ViewController : UIViewController

{

    CGPoint beginPoint;

    CGPoint nowPoint;

    BOOL isInButton;

}

@property (strong,nonatomic) IBOutlet UIButton *mButton;



- (void)viewDidLoad

{

    [super viewDidLoad];

    isInButton = YES;

// Do any additional setup after loading the view, typically from a nib.

}

- (IBAction)buttonclick:(id)sender

{

    NSLog(@"button tap");

}

- (void)shownslog

{

    if (isInButton) {

        [mButton setBackgroundImage:[UIImage imageNamed:@"meinv.jpg"] forState:UIControlStateNormal];

        NSLog(@"move in button");

    }else{

        [mButton setBackgroundImage:[UIImage imageNamed:@"images.jpeg"] forState:UIControlStateNormal];

        NSLog(@"move out button");

    }


}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    

    beginPoint = [touch locationInView:self.view];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    

    nowPoint = [touch locationInView:self.view];

    

    if (nowPoint.x <314&&nowPoint.x>6&&nowPoint.y>90&&nowPoint.y<313) {

        if (!isInButton) {

            isInButton = YES;

            [self shownslog]; 

        }

    }

    else

    {

        if (isInButton) {

            isInButton = NO;

            [self shownslog];

        }

    }

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{

    

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    if (isInButton) {

        isInButton = NO;

        [self shownslog];

    }

}


代码稍后会上传到cocoachina。关键字:moveshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值