简体   繁体   English

Sketch插件开发:是否有用于Sketch的API来解锁MSBitmapLayer的大小?

[英]Sketch Plugin Develop : Is there an API for Sketch to unlock the size of MSBitmapLayer?

The unlock size button in Sketh App Sketh App中的解锁大小按钮

I can click this button to unlock the size of a layer in Sketch App. 我可以单击此按钮来解锁Sketch App中的图层大小。 And then I can change the width/height ratio of the image. 然后,我可以更改图像的宽高比。 But I want my Sketch plugin to do this job instead of using my hand to click the button. 但是我希望我的Sketch插件可以完成这项工作,而不是用我的手来单击按钮。 Is there an API for Sketch to unlock the size of MSBitmapLayer ? 是否有用于Sketch的API来解锁MSBitmapLayer的大小?

I've tried " [layer setIsLocked:false] ", but it's not about the size lock. 我已经尝试过“ [layer setIsLocked:false] ”,但这与大小锁定无关。

Thank you very much. 非常感谢你。

The particular function you are looking for is setConstrainProportions() 您要查找的特定函数是setConstrainProportions()

Here is an example for you, It might help you in understanding it 这是为您提供的示例,可能有助于您理解它

function toggleConstrainProportions(context) {
  var doc = context.document
  var selection = context.selection

  // Toggles the currently selected item(s) 'Constrain Proportions'setting

  for (var i = 0; i < [selection count]; i++) {
    var s = [selection objectAtIndex: i]
    s.frame().setConstrainProportions(!s.constrainProportions())
  }
}

Hope this is helpful :) 希望这会有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM