2

UIDynamics アタッチメント動作を使用して 2 つの UIView をアタッチする「線」を表示するように UIDynamicBehaviors を構成する方法はありますか?

4

1 に答える 1

3

Apple開発者の Web サイトにあるDynamicsCatalogを参照してください。クラスAPLDecorationView内に描画される破線が表示されます。UIAttachmentBehavior接続を描画せずに、指定された要素間のアタッチメントを処理するだけです。

  1. したがって、プロジェクト内で使用する場合はAPLDecorationView.h 、ファイル内に挿入してください。
  2. ロープを追加するUIViews場所が初期化されたら、次の方法を使用します。

    trackAndDrawAttachmentFromView:toView:withAttachmentOffset:
    
  3. 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 に答える