简体   繁体   中英

iOS UIDynamics attachment behavior showing the line

是否可以将UIDynamicBehaviors配置为显示使用UIDynamics附加行为附加两个UIView的“行”?

Have a look at the DynamicsCatalog you can find on the apple developer website. You'll see a dashed line which will be drawn inside the class APLDecorationView . UIAttachmentBehavior is just responsible for handling an attachment between specified elements not drawing any connections.

  1. So if you want to use it inside your project, insert APLDecorationView.h inside your file.
  2. When your UIViews where the rope should be added, have been initialized, use following method:

     trackAndDrawAttachmentFromView:toView:withAttachmentOffset: 
  3. Customize inside the method the UIImage which should be displayed and maybe the size.

In my case it looked like this:

[(APLDecorationView *)self trackAndDrawAttachmentFromView:self.viewOne
                                                   toView:self.viewTwo
                                     withAttachmentOffset:CGPointZero];

And this is the modification of my 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];
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM