func lock() { let lockVIEw = UIImageVIEw(image: self.photoBackgroundVIEw.image!) var progressbar = UIVIEw(frame: CGRectMake(-self.vIEw.wIDth,self.vIEw.wIDth,20) let increment = progressbar.wIDth/self.photoBackgroundVIEw.wIDth var password = self.textFIEld.text! if password == "" { password = " " } var currentIndex = 0 let imageRect = CGRectMake(0,self.photoBackgroundVIEw.image!.size.wIDth,self.photoBackgroundVIEw.image!.size.height) UIGraphicsBeginImageContext(self.photoBackgroundVIEw.image!.size) let context = UIGraphicsGetCurrentContext() CGContextSaveGState(context) CGContextDrawImage(context,imageRect,self.photoBackgroundVIEw.image!.CGImage) for x in 0...Int(self.photoBackgroundVIEw.image!.size.wIDth) { print(x) progressbar.frame.origin.x += (CGfloat(x) * increment) self.vIEw.addSubVIEw(progressbar) for y in 0...Int(self.photoBackgroundVIEw.image!.size.height) { let pointcolor = lockVIEw.layer.colorOfPoint(CGPoint(x: x,y: y)) if currentIndex == Array(password.characters).count { currentIndex = 0 } let red = encrypt(pointcolor.components.red,passwordChar: Array(password.characters)[currentIndex],currentIndex: currentIndex,x: x,y: y) currentIndex++ if currentIndex == Array(password.characters).count { currentIndex = 0 } let green = encrypt(pointcolor.components.green,y: y) currentIndex++ if currentIndex == Array(password.characters).count { currentIndex = 0 } let blue = encrypt(pointcolor.components.blue,y: y) currentIndex++ CGContextSetRGBFillcolor(context,red,green,blue,pointcolor.components.Alpha) CGContextFillRect(context,CGRectMake(CGfloat(x),CGfloat(y),1,1)) } } CGContextRestoreGState(context) let newImage = UIGraphicsGetimageFromCurrentimageContext() self.photoBackgroundVIEw.image = newImage self.slIDeVIEw.addSubvIEw(photoBackgroundVIEw) self.vIEw.addSubvIEw(self.slIDeVIEw)}解决方法 您可以在 background thread中进行这些计算.
斯威夫特2:
let priority = disPATCH_QUEUE_PRIORITY_DEFAulTdispatch_async(dispatch_get_global_queue(priority,0)) { // Put the calculations here dispatch_async(dispatch_get_main_queue()) { // any updates of the UI need to be here to do them in the main thread after your background task. For example adding subvIEws }}
斯威夫特3:
见this answer
@H_419_34@ 总结以上是内存溢出为你收集整理的ios – 在大量计算过程中如何让屏幕停止冻结?全部内容,希望文章能够帮你解决ios – 在大量计算过程中如何让屏幕停止冻结?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)