uiviewcontroller中的设备方向更改

时间:2015-09-15 17:09:06

标签: ios swift

我想在设备方向更改时在UIViewcontroller中捕获事件并相应地更改视图内容。但是,执行此操作的函数似乎已被弃用。怎么解决这个问题?

1 个答案:

答案 0 :(得分:1)

在AppDelegate.swift里面的“didFinishLaunchingWithOptions”函数中放了:

Member = Ractive.extend({
  template : "<div>{{name}}</div>",
  computed : {male : function(){this.get('gender')=='m'}}
})

ff = new Ractive({
  el : '#container',
  template : "there are {{male_count}} males{{#family}}<member/>{{/family}}",
  components : {member : Member},
  data : {family : [
      {name:'Fred',gender:'m'},
      {name:'Wilma',gender:'f'},
      {name:'Rocky',gender: 'm'},
      {name:'Bubbles',gender: '?'}
  ]},
  computed : { male_count : function(){
    return _(this.findAllComponents('member')).filter(function(mem){return mem.get('male')}).length;
   }
  }
})

然后在AppDelegate类中放入以下函数:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)