Swift: Cropping a Screenshot without TabBar and NavigationBar

前端 未结 5 849
臣服心动
臣服心动 2021-01-05 14:43

I have a screenshot of the entire screen, screenshot, generated using the following:

let layer = UIApplication.sharedApplication().keyWindow!.l         


        
5条回答
  •  长发绾君心
    2021-01-05 15:17

    I think your crop CGRect is wrong.

    let crop = CGRectMake(0,
                          0,
                          self.view.frame.size.width,
                          self.view.frame.size.height + self.navigationController!.navigationBar.frame.height - self.tabBar.frame.size.height
                         )
    

    X: 0 and Y: 0 - start at 0, 0 respectively.

    Width: Capture the view's entire width

    Height: The entire view's height plus the height of the UINavigationBar minus the height of the UITabBar.

提交回复
热议问题