lizhengfeng

  用JS来开发MAC APP,目前我只知道两种,一是使用系统自带的脚本编辑器,二是node-webkit。

知道更多后回继续更新,以下都是在mac环境

一、使用MAC的脚本编辑器

1)项目相关

  开始: 打开位于Application > Utilities中的Apple Script Editor程序,选择开发语言为javascript

  运行:点击运行脚本或者opt + cmd +r

  输出: 在Launchpad - 其他 - 系统控制台可以看到

2)语法

  引用系统变量和类库:ObjC.import("要引用的库") 如:

ObjC.import("Cocoa");

  调用方法:$.类名.方法名(参数以逗号隔开) 这里的方法是用驼峰命名法连接起来的,如:

var window = $.NSWindow.alloc.initWithContentRectStyleMaskBackingDefer(
  $.NSMakeRect(0, 0, windowWidth, windowHeight),
  styleMask,
  $.NSBackingStoreBuffered,
  false
);

  但是在OC中的写法是:

NSWindow* window [[NSWindow alloc]
  initWithContentRect: NSMakeRect(0, 0, windowWidth, windowHeight)
  styleMask: styleMask,
  backing: NSBackingStoreBuffered
  defer: NO];

  子类:通过ObjC.registerSubclass({name:"",...})来创建类,字典可以包含name类名,superclass父类NSObject可以不写,protocols协议名,properties属性,method方法。

ObjC.registerSubclass({
  name: "AppDelegate",
  methods: {
    "btnClickHandler": {
      types: ["void", ["id"]],
      implementation: function (sender) {
        $.NSLog("Clicked!");
      }
    }
  }
});

type 全部类型列表 在这里

  

分类:

技术点:

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2021-12-27
  • 2021-11-05
  • 2021-10-01
  • 2021-08-05
  • 2021-09-05
  • 2022-01-13
猜你喜欢
  • 2021-11-17
  • 2021-04-09
  • 2022-02-01
  • 2022-01-15
  • 2021-07-17
  • 2021-08-09
  • 2022-01-31
相关资源
相似解决方案