作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的 ipad 应用程序使用 spliviewcontroller。我还对 spliview 左侧的 uitableview 实现了重新排序。我想要实现的是用户可以对 tableCell 重新排序,但不需要触摸三个白条。用户应该能够触摸单元格上的任何位置并重新排序。可能吗?
最佳答案
下面的类将隐藏重新排序控件并使整个 UITableViewCell 可触摸以进行重新排序。此外,它还负责将内容 View 的大小重新调整为其原始大小,这对于自动布局非常重要。
@interface UITableViewCellReorder : UITableViewCell
{
__weak UIView *_reorderControl;
}
@implementation UITableViewCellReorder
#define REORDER_CONTROL_CLASSNAME @"UITableViewCellReorderControl"
/*
Override layoutSubviews to resize the content view's frame to its original size which is the size
of the cell. This is important for autolayout!
Do not call this method on super, as we don't need any further layouting wihtin the cell itself.
*/
- (void)layoutSubviews
{
self.contentView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self setAndHideReorderControl];
}
/*
Find the reorder control, store a reference and hide it.
*/
- (void) setAndHideReorderControl
{
if (_reorderControl)
return;
// > iOS 7
for(UIView* view in [[self.subviews objectAtIndex:0] subviews])
if([[[view class] description] isEqualToString:REORDER_CONTROL_CLASSNAME])
_reorderControl = view;
// < iOS 7
if (!_reorderControl)
for(UIView* view in self.subviews)
if([[[view class] description] isEqualToString:REORDER_CONTROL_CLASSNAME])
_reorderControl = view;
if (_reorderControl)
{
[_reorderControl setHidden:YES];
}
}
#pragma mark - Touch magic
/*
Just perform the specific selectors on the hidden reorder control to fire touch events on the control.
*/
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(beginTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(beginTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}
[super touchesBegan:touches withEvent:event];
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(continueTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(continueTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}
[super touchesMoved:touches withEvent:event];
[self.nextResponder touchesMoved:touches withEvent:event];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(cancelTrackingWithEvent:)])
{
[_reorderControl performSelector:@selector(cancelTrackingWithEvent:) withObject:event];
}
[super touchesCancelled:touches withEvent:event];
[self.nextResponder touchesCancelled:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_reorderControl && [_reorderControl respondsToSelector:@selector(endTrackingWithTouch:withEvent:)])
{
UITouch * touch = [touches anyObject];
[_reorderControl performSelector:@selector(endTrackingWithTouch:withEvent:) withObject:touch withObject:event];
}
[super touchesEnded:touches withEvent:event];
[self.nextResponder touchesEnded:touches withEvent:event];
}
@end
关于iphone - 如何在不显示重新排序控件的情况下重新排序 uitableviewcell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683837/
我是一名优秀的程序员,十分优秀!