我刚从 Apple 开发者门户网站下载 DynamicsCatalog.xcodeproj,但出现此错误:
“UIAttachmentBejavior”没有可见的@interface decleares 选择器 initwititem
在这一行:
UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 point:attachmentPoint attachedToAnchor:squareCenterPoint];
在 APLAttachmentsViewController.m 中
这是该行的上下文:
- (void)viewDidLoad
{
[super viewDidLoad];
UIDynamicAnimator* animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UICollisionBehavior* collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1]];
CGPoint squareCenterPoint = CGPointMake(self.square1.center.x, self.square1.center.y - 100.0);
CGPoint attachmentPoint = CGPointMake(-25.0, -25.0);
/*
By default, an attachment behavior uses the center of a view. By using a small offset, we get a more interesting effect which will cause the view to have rotation movement when dragging the attachment.
*/
UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 point:attachmentPoint attachedToAnchor:squareCenterPoint];
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
// Show visually the attachment points
self.redSquare.center = attachmentBehavior.anchorPoint;
self.blueSquare.center = CGPointMake(25.0, 25.0);
[animator addBehavior:attachmentBehavior];
self.animator = animator;
self.attachmentBehavior = attachmentBehavior;
}
你们中有人知道为什么或如何修复此演示代码吗?
最佳答案
看看 class reference for UIAttachmentBehavior : initWithItem:point:attachedToAnchor:
没有声明,它似乎在某个时候被删除了。使用其他初始化程序之一:
– initWithItem:attachedToAnchor:
– initWithItem:attachedToItem:
– initWithItem:offsetFromCenter:attachedToAnchor:
– initWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:
您正在使用的选择器实际上已重命名为 initWithItem:offsetFromCenter:attachedToAnchor:
关于iphone - 'UIAttachmentBehavior' 没有可见的@interface 在 DynamicsCatalog.xcodeproj 中声明选择器 initWithItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018203/