Dou*_*ith 9 objective-c uiview uigesturerecognizer ios uipangesturerecognizer
这是一个发生的视频:
基本上,如果我在平移时更改UIImageView(X)的图像属性,它会将视图中的所有控件恢复到原始的未打开位置.(它们都嵌入在UIView中,因此我可以"平移单元格",而UIImageViews在视图之外并且是独立的.)
如果我不更改图像:
为了记录,我改变图像,当用户平移一定量,我相信80点.
这是代码:
// Only allow the cell to be moved 100 pixels left or right
if (xPos <= 100 && xPos >= -100) {
// Move our cell to the xPos we defined
CGRect slidingViewFrame = self.slidingView.frame;
slidingViewFrame.origin = CGPointMake(xPos - 100, 0);
self.slidingView.frame = slidingViewFrame;
if (xPos >= 80) {
if (_removeIconIsActive == NO) {
// Change remove icon to a red, active state and animate the change
self.removeIconImageView.image = [UIImage imageNamed:@"remove-icon-active.png"];
_removeIconIsActive = YES;
}
CGRect removeIconFrame = self.removeIconImageView.frame;
removeIconFrame.origin = CGPointMake(40, 35);
self.removeIconImageView.frame = removeIconFrame;
}
}
Run Code Online (Sandbox Code Playgroud)
视图在故事板中设置,但移动和操作都是在代码中完成的.
这是故事板布局:

这是处理细胞平移的完整方法:https://gist.github.com/anonymous/c51c7cb2997c89094f08
如果您使用的是自动布局,则根本不应修改框架属性.框架是应用布局约束的结果,而不是"写入"属性.
我想你会有一个约束来设置你的视图的x位置.IBOutlet为该约束创建一个,而不是修改您的约束frame,修改constant约束的属性.然后调用layoutIfNeeded视图.
如果没有看到更多关于你的观点,约束和出口,我不能给你最终的代码,但你会以这样的结局:
self.leftConstraint.constant = xPos - 100.f;
[self.slidingView setNeedsUpdateConstraints];
[self.slidingView layoutIfNeeded];
Run Code Online (Sandbox Code Playgroud)
我对正在发生的事情的解释是,设置图像会改变图像视图的内在大小,这会使约束自身重新计算,将所有内容都回到起始位置.一旦你滑动另一个像素,你再次开始,frame属性再次获胜.
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
411 次 |
| 最近记录: |