Rah*_*hul 6 objective-c uislider ios
我在我的一个App中实现了Vertical Slider UISlider.当滚动结束/完成时,我将使用Slider值向服务器发送命令.有时当我快速向上/向下滚动并释放时,滑块值在发送命令之前和发送命令之后变得不匹配.
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Value of Slider before sending command=%f",self.value);
[self sendCommand]; // Here value is something else
[super touchesEnded:touches withEvent:event];
NSLog(@"Slider value after sending command=%f",self.value); // Here value changed
}
Run Code Online (Sandbox Code Playgroud)
但如果我在发送命令之前发出超级调用,那么一切正常.请解释是否有人知道为什么会这样.
[super touchesEnded:touches withEvent:event];
Run Code Online (Sandbox Code Playgroud)
更有趣的事实是,如果我不打电话给超级,那么一切都运作良好.
小智 0
这是因为该方法[super touchesEnded:touches withEvent:event];是滑块根据交互更新其值的地方。所以在调用 super 之前该值已经过时了。
对 super 的调用通常应该是重写方法的第一行。
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |