iphone - 'UIAttachmentBehavior' 没有可见的@interface 在 DynamicsCatalog.xcodeproj 中声明选择器 initWithItem

标签 iphone ios ipad xcode5

我刚从 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/

相关文章:

ios - 如果我创建个人帐户而不是公司帐户,是否可以让多个开发人员测试我的 iPhone/iPad 应用程序?

iphone - iBooks 能够读取其他应用程序沙盒中的文件

iOS 7 地址簿未排序

ios - 静态NSString * const-在iOS中引发错误 'Unknown type name ' NSString''

ios - 以编程方式创建 iOS UIStackView

ios - 是否不可能将 subview 添加到我的 UITableViewCell 的 contentView 并使其与 contentView 宽度相等?

ios - 为 iOS5 和 Storyboard更新 MGSplitViewController 的已知努力?

iphone - 点击 X 按钮时从 UISearchBar 中关闭键盘

iphone - 当 UINavigationBar 隐藏/显示时如何防止 View 调整大小/转换

iphone - popToRootViewControllerAnimated 并释放所有 View