ios基础考试题1,实现按钮点击改变位置和图片的透明度和动画的使用
考察frame,center,bounds的坐标,改变,动画的使用,图片容器的UIImageView的透明度等知识
oc写法
//// ViewController.m// kaoshiTi1//// Created by lujun on /5/19.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *babyView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];}- (IBAction)click:(id)sender {CGRect rect = self.babyView.frame;rect.origin.y =self.view.frame.size.height;self.babyView.frame = rect;self.babyView.alpha = 1.0;[UIView animateWithDuration:0.5 animations:^{CGPoint pCenter = self.babyView.center;pCenter.y = self.view.frame.size.height * 0.5;self.babyView.center = pCenter;} completion:^(BOOL finished) {[UIView animateWithDuration:1.0 animations:^{self.babyView.alpha = 0.0;}];}];}@end
斯为芙特写法
//// ViewController.swift// 01-考试题1//// Created by lujun on /5/19.//import UIKitclass ViewController: UIViewController {@IBOutlet weak var babyView: UIImageView!@IBAction func click(_ sender: Any) {self.babyView.frame.origin.y = self.view.frame.heightself.babyView.alpha = 1.0UIView.animate(withDuration: 0.25) {self.babyView.center.y = self.view.frame.height * 0.5} completion: {(finished: Bool) inUIView.animate(withDuration: 1.0) {self.babyView.alpha = 0.0}}}override func viewDidLoad() {super.viewDidLoad()}}