
let iconmargin: CGfloat = 10.0let iconW: CGfloat = 80.0let iconH: CGfloat = 80.0let cellIDIEntifIEr = "cellIDentifIEr"let screenHeight = UIScreen.mainScreen().bounds.size.heightlet screenWIDth = UIScreen.mainScreen().bounds.size.wIDth
在vIEwDIDLoad中
// 这里创建tablevIEw的代码就不贴出来了 self.createSubvIEws() // 调整tablevIEw的位置 self.tableVIEw.contentInset = UIEdgeInsetsMake(200,0,0); // 把图片设置到对应位置上 imagetopVIEw = UIImageVIEw.init(frame: CGRectMake(0,screenWIDth,200)) // 把加载的图片设置需要的大小 let oldImage = UIImage.init(named: "1111") imagetopVIEw.image = self.originImagescaletoSize(oldImage!,size: CGSizeMake(screenWIDth,200)) // 这里是为了让图片宽度随着高度的拉伸而拉伸 imagetopVIEw.contentMode = UIVIEwContentMode.ScaleAspectFill; self.vIEw.addSubvIEw(imagetopVIEw) imageIcon = UIImageVIEw.init(frame: CGRectMake(iconmargin,200 - (iconmargin + iconH),iconW,iconH)) imageIcon.layer.cornerRadius = 7.5; imageIcon.image = UIImage.init(named: "01") imageIcon.clipsToBounds = true; //自动布局,自适应顶部 imageIcon.autoresizingMask = UIVIEwautoresizing.Flexibletopmargin imagetopVIEw.addSubvIEw(imageIcon)
设置图片的大小
func originImagescaletoSize(image: UIImage,size: CGSize)->UIImage { UIGraphicsBeginImageContextWithOptions(size,false,0) image.drawInRect(CGRectMake(0,size.wIDth,size.height)) let scaleImage: UIImage = UIGraphicsGetimageFromCurrentimageContext() UIGraphicsEndImageContext() return scaleImage }
监听滚动
func scrollVIEwDIDScroll(scrollVIEw: UIScrollVIEw) { // 偏移量y的变化 let y: CGfloat = scrollVIEw.contentOffset.y; print("y ------ \(y)") if y < -200 { var frame: CGRect = self.imagetopVIEw.frame; frame.size.height = -y; self.imagetopVIEw.frame = frame; } } 总结 以上是内存溢出为你收集整理的Swift 图片下拉放大全部内容,希望文章能够帮你解决Swift 图片下拉放大所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)