如何通过参数调用函数

时间:2018-08-02 07:33:52

标签: swift

如何调用这样的函数?

func calculateAndApplyPageHeight() {
    var height : CGFloat = 0
    for v in self.pageView.subviews {
        height += v.frame.height
    }
    print("Height = \(height)!")
    height = height + 40
    if height != self.pageViewHeightConstraint.constant {
        self.pageViewHeightConstraint.constant = height
        self.view.setNeedsDisplay()
    }
}
@IBAction func showSelectedView(_ sender: UISegmentedControl) {

    switch sender.selectedSegmentIndex
    {
    case 0:
        view1.isHidden = false
        view2.isHidden = true
    case 1:
        view1.isHidden = true
        view2.isHidden = false

    default:
        break
    }
    calculateAndApplyPageHeight()
}

这是我的代码

func addWatermark(inputURL: URL, outputURL: URL, handler:@escaping (_ exportSession: AVAssetExportSession?)-> Void) {

    }
  

无法将类型'(()-> Void).Type'的值转换为预期参数   输入'((AVAssetExportSession?)->无效'

3 个答案:

答案 0 :(得分:2)

首先,在Swift 3+中不要使用 SimpleDateFormat dateFormat1 = new SimpleDateFormat("ddMMyyyy"); Date date1 = new Date(); LocalDate date = DateTimeFormat.forPattern("ddMMyyyy").parseLocalDate(dateFormat1.format(date1)); System.out.println("Century=" + date.getCenturyOfEra()); String usFormat = DateTimeFormat.forPattern("ccyy/MM/dd").print(date); System.out.println(usFormat); 。使用本机NSURL,这可以避免丑陋的桥式转换。

调用该函数的语法应该看起来像

URL

addWatermark(inputURL: videoURL!, outputURL: videoURL) { exportSession in } 是传递的exportSession参数

答案 1 :(得分:1)

尝试这样的结尾闭包:

addWatermark(inputURL: videoURL! as URL, outputURL: videoURL! as URL) { exportSession in 

}

或更详细的选择:

addWatermark(inputURL: videoURL, outputURL: videoURL, handler: { exportSession in

})

答案 2 :(得分:0)

打电话给你这个功能:

<ListView ItemsSource="{Binding PickingParts}"
          SeparatorVisibility="None"
          SeparatorColor="Transparent"
          RowHeight="100"
          SelectedItem="{Binding SelectedPickingPart, Mode=TwoWay}">

    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <local:PickingPartItemTemplate />
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>

</ListView>