gpt4 book ai didi

objective-c - UIGravityBehavior 不工作

转载 作者:太空狗 更新时间:2023-10-30 03:49:58 27 4
gpt4 key购买 nike

我正在努力学习 UIKit Dynamics。
我创建了一个框 View 并在其上添加了 UIGravityBehavior,但是当我运行该项目时没有任何反应!

Viewcontroller.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];

UIView* box = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 100, 100)];
box.backgroundColor = [UIColor blackColor];
[self.view addSubview:box];
UIGravityBehavior* gravityBehaviour = [[UIGravityBehavior alloc]init];
[gravityBehaviour addItem:box];
UIDynamicAnimator* myAnimator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
[myAnimator addBehavior:gravityBehaviour];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

这是我的view controller.m文件。
程序有什么问题?

最佳答案

如果想在ViewDidLoad中使用,需要将UIDynamicAnimator和UIGravityBehavior声明为当前VC的属性。自动引用计数将在 ViewDidLoad 完成后释放这些对象。

问候

关于objective-c - UIGravityBehavior 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20439642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com