swift

iOS 跳转到任意某个rootViewController

 

 

x 代表第几个根视图,任意视图跳转哦

 

self.tabBarController.selectedViewController = self.tabBarController.childViewControllers[X];

 

[self.navigationController popToRootViewControllerAnimated:YES];

 

iOS ViewController 截屏方法

vc.backimage = self.snapView(targetView: self.view)截屏方法

//截屏
func snapView(targetView: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(targetView.bounds.size, false, 0)
// iOS7.0 之后系统提供的截屏的功能
targetView.drawHierarchy(in: targetView.bounds, afterScreenUpdates: false)

let snapdImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return snapdImage!

}

//改变状态栏颜色

    override var preferredStatusBarStyle: UIStatusBarStyle {

        if statusBarShouldLight {

            return .lightContent

        } else {

            return .default

        }

    }

 

    /// 更改图片颜色

    public func imageWithTintColor(color : UIColor) -> UIImage{

        UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)

        let context = UIGraphicsGetCurrentContext()

        context?.translateBy(x: 0, y: self.size.height)

        context?.scaleBy(x: 1.0, y: -1.0)//kCGBlendModeNormal

        context?.setBlendMode(.normal)

        let rect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)

        context?.clip(to: rect, mask: self.cgImage!)

        color.setFill()

        context?.fill(rect)

        let newImage = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        return newImage!

    }

//scrollView偏移问题

只要scrollView是其父视图上的第一个子视图,且navigationBar不隐藏的情况下,添加到scrollView里的视图,都会默认下移64个像素。ios11好像没问题,解决冲突 在前面加个view或禁止系统偏移  vc.automaticallyadjustsScrollviewInsets =NO 这个好像不行

 

 

 

 

///hidesBottomBarWhenPushed push跳转时隐藏/显示UITabBar

self.hidesBottomBarWhenPushed = false

//关闭视图过渡动画 

        UIView.performWithoutAnimation {

tableView刷新会跳动之类的这些奇怪的动画,把刷新方法放在这里就可以了

        }

 

 

 

 

你可能感兴趣的:(swift)