我创建了一个自定义日期选择器。我想从下到上显示它。但它没有显示它从上到下显示。
这是代码。
let frame:CGRect = CGRect(x: 0, y: 600, width: self.view.frame.width, height: self.view.frame.height/3)
self.datePicker = CustomDatePicker.instanceFromNib(frame: frame) as? CustomDatePicker
self.datePicker?.configureDatePicker()
datePicker?.customPickerDelegate = self
UIView.animate(withDuration: 1.5, animations: {
DILog.print(items: "Updated Y is \(self.view.frame.height - self.view.frame.height/3)")
let frame:CGRect = CGRect(x: 0, y: 300, width: self.view.frame.width, height: self.view.frame.height/3)
self.datePicker = CustomDatePicker.instanceFromNib(frame: frame) as? CustomDatePicker
}, completion: { (value) in
})
self.view.addSubview(self.datePicker!)
答案 0 :(得分:1)
首先必须在动画之前添加动画选择器,其次你不能在动画内再次从笔尖加载选择器
this.state = {
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
},
<MapView
provider={ PROVIDER_GOOGLE }
style={ styles.map }
initialRegion={this.state.region}
onPress={this.onMapPress}
minZoomLevel={10} //to zoom map to my location
/>
答案 1 :(得分:0)
首先:在动画制作之前,在父视图中添加datePicker。除非你这样做,否则它不可见 秒:您的选择器y在动画块中不是动态的。它应该是原始y - 选择器的高度。
总代码:
let frame:CGRect = CGRect(x: 0, y: 600, width: self.view.frame.width, height: self.view.frame.height/3)
self.datePicker = CustomDatePicker.instanceFromNib(frame: frame) as? CustomDatePicker
self.datePicker?.configureDatePicker()
datePicker?.customPickerDelegate = self
self.view.addSubview(self.datePicker!)
UIView.animate(withDuration: 1.5, animations: {
DILog.print(items: "Updated Y is \(self.view.frame.height - self.view.frame.height/3)")
let frame:CGRect = CGRect(x: 0, y: 600 - self.view.frame.height/3, width: self.view.frame.width, height: self.view.frame.height/3)
self.datePicker = CustomDatePicker.instanceFromNib(frame: frame) as? CustomDatePicker
}, completion: { (value) in
})
答案 2 :(得分:0)
使用一些很酷的动画,您可以执行以下操作...
//configure date picker and add it
//animate it in this way
UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.datePicker.frame = CGRect(x: 0, y: 300, width: self.view.frame.width, height: self.view.frame.height/3)
}) { (isDone) in
}