我有一個UIView子類,包含幾個子視圖,我想拖動&拖放到UICollectionView中包含的其他UIViews之一。當拖動開始時,我想將拖動的視圖從其當前的大小縮放到拖動持續時間內的較小值(原始大小過大,以至於無法首先縮放它時方便地選擇放置目標)到目前爲止,我有這樣的:IOS拖放與縮放
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.superview bringSubviewToFront:self];
self.transform = CGAffineTransformMakeScale(0.3f, 0.3f);
startLocation = ([[touches anyObject] locationInView:self]);
startLocation = CGPointApplyAffineTransform(startLocation, self.transform);
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self];
float dx = pt.x - startLocation.x;
float dy = pt.y - startLocation.y;
CGPoint newCenter = CGPointApplyAffineTransform (CGPointMake(self.center.x + dx, self.center.y + dy), self.transform);
self.center = newCenter;
}
這是一個開始,因爲它縮放拖動的UIView,我想它,並讓我將它拖到;但是,拖動的UIView不會直接用鼠標指針移動(我在模擬器上運行)。當圖像靠近模擬器屏幕的左上角時,鼠標指針&拖動視圖在一起;但是當我離開屏幕的右上角時,視圖不再直接用鼠標指針移動;鼠標指針似乎以大約2:1的比例移動到拖動的UIView的移動。
第二個問題是,當拖動結束時,如果該項目沒有被刪除,我需要將UIView返回到它的原始比例,然後再將其重新附加到它的超級視圖,並且還沒有完全想到如何做到這一點。
感謝任何幫助,包括有關更好方法的建議,如果我完全偏離此處。 (我知道還有其他的東西需要在隔離放置目標和放棄時完成,但我想我知道那裏需要做什麼)。
感謝您的任何指導。
正則表達式
好的,我明白了,我想我會發布代碼,以防萬一別人需要它。我在這裏發現了另一篇文章,其中有類似的問題: – RegularExpression 2013-02-20 17:50:06