[英]iOS UIDynamics attachment behavior showing the line
是否可以将UIDynamicBehaviors配置为显示使用UIDynamics附加行为附加两个UIView的“行”?
Have a look at the DynamicsCatalog you can find on the apple developer website. 看一下您可以在Apple开发人员网站上找到的DynamicsCatalog 。 You'll see a dashed line which will be drawn inside the class APLDecorationView . 您将看到一条虚线,它将在APLDecorationView类中绘制 。 UIAttachmentBehavior
is just responsible for handling an attachment between specified elements not drawing any connections. UIAttachmentBehavior
仅负责处理指定元素之间的附件,而不绘制任何连接。
APLDecorationView.h
inside your file. 因此,如果要在项目中使用它, APLDecorationView.h
在文件中插入APLDecorationView.h
。 When your UIViews
where the rope should be added, have been initialized, use following method: 初始化应在其中添加绳索的UIViews
,请使用以下方法:
trackAndDrawAttachmentFromView:toView:withAttachmentOffset:
UIImage
which should be displayed and maybe the size. 在方法内部自定义应显示的UIImage
以及大小。 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
: 这是我的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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.