您的位置:首页 > 移动开发 > IOS开发

ios-center 和 bounds用法

2015-07-29 10:30 344 查看
//
//  ViewController.m
//  MovePicture
//
//  Created by YaguangZhu on 15/7/28.
//  Copyright (c) 2015年 YaguangZhu. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)move:(UIButton *)sender;

- (IBAction)scale:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIButton *btnIcon;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)move:(UIButton *)sender {

CGPoint centerPoint =  self.btnIcon.center;
switch (sender.tag) {
case 10:
NSLog(@"up");
centerPoint.y -=10;
break;
case 20:
NSLog(@"right");
centerPoint.x +=10;
break;
case 30:
NSLog(@"down");
centerPoint.y +=10;
break;
case 40:
NSLog(@"left");
centerPoint.x -=10;
break;
default:
break;

}

self.btnIcon.center = centerPoint;

}

- (IBAction)scale:(UIButton *)sender {

CGRect originBounds = self.btnIcon.bounds;
if (sender.tag == 100) {
NSLog(@"big");
originBounds.size.height +=10;
originBounds.size.width +=10;

self.btnIcon.bounds = originBounds;
}else
{    NSLog(@"small");
originBounds.size.height -=10;
originBounds.size.width -=10;

self.btnIcon.bounds = originBounds;

}

self.btnIcon.bounds = originBounds;
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: