UIDynamics アタッチメント動作を使用して 2 つの UIView をアタッチする「線」を表示するように UIDynamicBehaviors を構成する方法はありますか?
1 に答える
3
Apple開発者の Web サイトにあるDynamicsCatalogを参照してください。クラスAPLDecorationView内に描画される破線が表示されます。UIAttachmentBehavior
接続を描画せずに、指定された要素間のアタッチメントを処理するだけです。
- したがって、プロジェクト内で使用する場合は
APLDecorationView.h
、ファイル内に挿入してください。 ロープを追加する
UIViews
場所が初期化されたら、次の方法を使用します。trackAndDrawAttachmentFromView:toView:withAttachmentOffset:
UIImage
メソッド内で表示されるものとサイズをカスタマイズします。
私の場合、次のようになりました。
[(APLDecorationView *)self trackAndDrawAttachmentFromView:self.viewOne
toView:self.viewTwo
withAttachmentOffset:CGPointZero];
そして、これは私の変更ですAPDecorationView
:
NSInteger iRopeElements = ( isiPad ) ? 15 : 20;
for (NSUInteger i=0; i < iRopeElements; i++)
{
UIImage *ropeElement = [UIImage imageNamed:@"rope_element"];
CALayer *layerRope = [CALayer layer];
layerRope.contents = (__bridge id)(ropeElement.CGImage);
CGFloat fRopeWidth = attachedView.frame.size.width * 0.3f;
layerRope.bounds = CGRectMake(0, 0, fRopeWidth, fRopeWidth / 1.64f);
layerRope.anchorPoint = CGPointMake(0.5, 0);
[self.layer insertSublayer:layerRope atIndex:0];
[self.attachmentDecorationLayers addObject:layerRope];
}
于 2014-08-04T14:43:10.040 に答える