【发布时间】:2014-12-18 14:23:39
【问题描述】:
我查看了UIButton can't be touched while animated with UIView animateWithDuration,但答案对我没有帮助。
for (UIButton *button in self.buttonsOutletCollection)
这部分是令人困惑的部分。我的按钮不是 IBOutletCollection 的一部分,所以这不起作用。我用它来移动按钮:
- (void) squareOneMover {
CGRect oldFrame = _squareOne.frame;
[UIView animateWithDuration:2
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect newFrame = CGRectMake(oldFrame.origin.x , oldFrame.origin.y + 500, oldFrame.size.width, oldFrame.size.height);
_squareOne.frame = newFrame;
}
completion:nil
];
}
我不想少量移动按钮,因为我需要五个按钮,而且效率很低。
有人可以为我提供类似于上述问题的答案,即UIButtons 不包含在任何数组中吗?
编辑:
UIButton在接口文件中定义并连接到Interface Builder,分别是strong和nonamatic
编辑 2:我现在正在使用 animateWithDuration:delay:options:animations:completion:,但它仍然不起作用。
我使用此代码来检测按钮是否被按下。
- (void)squareOnePressed:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if ([self.squareOne.layer.presentationLayer hitTest:touchLocation])
{
NSLog(@"YO");
}
}
但是当按下按钮时仍然没有任何反应......那么我该如何编程^^^^
【问题讨论】:
-
在哪里定义以及如何定义 UIButton?你的问题太宽泛了。
-
那你有没有在 animateWithDuration:delay:options:animations:completion: 中添加 UIViewAnimationOptionAllowUserInteraction 的选项?
-
UIButton是否连接到 Interface Builder?如果是这样,您需要将其设为weak。 -
@ray 它是连接的,但它必须保持强大,因为我使用以编程方式编写的约束。
self.squareOne = [[UIButton alloc] init];按钮弱时产生错误 -
如果你在 IB 中创建了那个按钮,你不应该在 self.squareOne 上调用 alloc init ——它已经实例化了,你为什么要创建一个新的?
标签: ios objective-c uibutton