小编THO*_*THO的帖子

Arc4random错误:"二进制表达式的操作数无效('float'和'float')"

我想在某个视图中的随机位置创建一个按钮.我搜索并阅读了一些SO主题但是我找不到解决问题的方法.

这是我的代码:

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonRect = button1.frame;
buttonRect.size = CGSizeMake(100, 100);
button1.frame = buttonRect;

[self.arr addObject:button1];

int r = ([button1 frame].size.width)/2;

int x = r + (arc4random() % (self.view.frame.size.width - button1.frame.size.width));
int y = r + (arc4random() % (self.view.frame.size.height - button1.frame.size.height));
//ERROR:Invalid operands to binary expression ('float' and 'float')

[button1 setCenter:CGPointMake(x, y)]; 
Run Code Online (Sandbox Code Playgroud)

uibutton arc4random ios

2
推荐指数
1
解决办法
2187
查看次数

标签 统计

arc4random ×1

ios ×1

uibutton ×1