1
我想在另一個UIView或其他元素上拖動UICollectionViewCell。 我已經創建了UICollectionViewCell的子類。在另一個元素上拖動UICollectionViewCell
這是我的手機類,UICollectionViewCell的子類:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.dragObject=self;
self.homePosition = CGPointMake(self.frame.origin.x,
self.frame.origin.y);
[self.superview.superview bringSubviewToFront:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self.superview];
CGRect newDragObjectFrame = CGRectMake(touchPoint.x - touchOffset.x,
touchPoint.y - touchOffset.y,
self.frame.size.width,
self.frame.size.height);
self.frame = newDragObjectFrame;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect newFrame = CGRectMake(self.homePosition.x, self.homePosition.y,
self.frame.size.width,
self.frame.size.height);
[UIView animateWithDuration:0.2
animations:^{
self.frame = newFrame;
}];
}
我可以拖動和UICollectionView降大任於UICollectionViewCell。但我無法在屏幕上的另一個元素上拖動單元格。例如另一個UICollectionView或UIView。
如果我將clipToBounds屬性設置爲「false」,那麼我可以在任何位置拖動單元格,但不會隱藏溢出內容(如滾動單元格)。
在這張照片,clipToBounds =假:
輝煌,謝謝... – onivi