类型王者荣耀的摇杆

github:https://github.com/yhl714387953/KingOfGlory

https://github.com/xingjizhao/JoyStickView


4323429-a738f6c9b5417a16.gif

原生实现iOS摇杆

调用实例

// 控制器

float width = 120;

XXJoyStickView* v = [[XXJoyStickView alloc]initWithFrame:CGRectMake(10, self.view.frame.size.height-width-10, width, width)];

v.angleBlock = ^(float sinX, float sinY) {

[ws moveViewWithSinX:sinX sinY:sinY];

};

[self.view addSubview:v];

block中的sinX和sinY是当前方向的角度,x以top为0度,y以right为0度

视图配合方向角度的移动入下

- (void)moveViewWithSinX:(float)sinX sinY:(float)sinY {

float x = self.moveView.frame.origin.x+self.moveViewSpeed*sinf(sinX);

float y = self.moveView.frame.origin.y+self.moveViewSpeed*sinf(sinY);

self.moveView.frame = CGRectMake(x, y, self.moveView.frame.size.width, self.moveView.frame.size.height);

}

猜你喜欢

转载自blog.csdn.net/weixin_33805557/article/details/90825440