如何在Swift中调用Objective C UIView的initWithFrame

Ame*_*mey 6 uiview ios swift

这就是我在Obejective C中调用UIView DraggableViewBackground的方法,它工作得很好但是如何在Swift中做同样的事情

 DraggableViewBackground *draggableBackgroundforurl = [[DraggableViewBackground alloc]initWithFrame:self.view.frame];
Run Code Online (Sandbox Code Playgroud)

我的DraggableViewBackground在Objective C中,我希望在单击按钮时将其设置为子视图

Kri*_*lci 9

let draggableBackgroundforurl = DraggableViewBackground(frame: self.view.frame);
Run Code Online (Sandbox Code Playgroud)

这应该够了吧.

您可以在这种情况下查找区别let并var确定最适合您需求的区别.let不能改变,var可以.


Jor*_*anC 7

来自UIView文档.只需使用普通的swift初始化程序.

在此输入图像描述