【问题标题】:Really need to translate this CGRect code from Objective-C to Swift [closed]确实需要将此 CGRect 代码从 Objective-C 转换为 Swift [关闭]
【发布时间】:2014-09-21 17:21:46
【问题描述】:

我需要在单击 UIButton 时更改其位置 (iOS)。我发现一个教程说:

-(IBAction) move {    
   CGRect frame = [buttonMove frame];    
   frame.origin.x = 100;    
   frame.origin.y = 10;    
   [buttonMove setFrame: frame];    
}

有人可以帮我把它翻译成 Swift 吗? Link to the tutorial

【问题讨论】:

  • 您应该自己尝试转换,展示您尝试过的内容并询问哪些内容无法正常工作...

标签: ios objective-c position swift translate


【解决方案1】:

这里没什么难的,只是语法问题

@IBAction func move() {
    var frame = buttonMove.frame;
    frame.origin.x = 100
    frame.origin.y = 10;
    buttonMove.frame = frame;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多