标签:swift教学视频 swift教程 swift计算机 swift qq代码
很多伙伴们们总是认为缩放图片的时候很是麻烦,因为不知道从哪里下手,特别是面对新的开发语言,其实图片缩放有很多种方法,但是万变不离其宗,那就是frame,所以,不要想的那么高大上。下面是一个利用蒙板实现的图片缩放demo,感兴趣的伙伴们可以看一下。
//
// ViewController.swift
// 图片的缩放
//
// Created by 悦兑科技 on 15/1/15.
// Copyright (c) 2015年 BSY. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var imageview = UIImageView()
var button = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
// 初始化UIImageView
var imageview:UIImageView = UIImageView(frame: CGRectMake(100, 100, 100, 100))
var image = UIImage(named: "1024")
imageview.image = image
self.view.addSubview(imageview)
self.imageview = imageview
// 初始化UIButton(蒙板)
var button:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
var frame = imageview.frame
button.frame = frame
self.view.addSubview(button)
button.addTarget(self, action: "changeImage:", forControlEvents: UIControlEvents.TouchUpInside)
self.button = button
self.button.selected = false
}
// 初始化UIButton方法实现
func changeImage(sender:UIButton){
[UIView .beginAnimations("", context: nil)];
[UIView .setAnimationDelay(0.1)];
[UIView .setAnimationDuration(0.5)];
self.button.selected = !sender.selected
if(self.button.selected == true){
self.imageview.frame = UIScreen.mainScreen().bounds
}else if(self.button.selected == false){
self.imageview.frame = CGRectMake(100, 100, 100, 100)
[UIView.commitAnimations];}}
}
标签:swift教学视频 swift教程 swift计算机 swift qq代码
原文地址:http://blog.csdn.net/mjbaishiyun/article/details/42773341