改变视图的放大 缩小

- (void)loadView
{
    //必须先初始化一个底层的 View
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    self.view = aView;
    [aView release];
   
    UIView *twoView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 60,60)];
    twoView.backgroundColor = [UIColor blueColor];
    //自动调整大小//自动调整宽和高
    twoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
   
    UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    oneView.tag = 1000;         //设置View的tag值,可以在方法外通过tag值取得这个View
    oneView.backgroundColor = [UIColor redColor];
    oneView.alpha = 1.0f;//设置透明度(0.1 <-> 1)默认是1.0
    oneView.center = CGPointMake(160, 300);//设置View的中心点
    NSLog(@"bounds = %@",NSStringFromCGRect(oneView.bounds));//输出oneView的尺寸
    oneView.userInteractionEnabled = YES;//是否接收响应点击
    oneView.autoresizesSubviews = YES;//是否自动调整subviews的大小,默认YES。
   
    [oneView addSubview:twoView];
    [twoView release];
   
    [self.view addSubview:oneView];
    [oneView release];
   
   
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btn setTitle:@"UP" forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 0, 100, 30);
    btn.center = CGPointMake(160, 460-30);
    [btn addTarget:self action:@selector(up:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];


-(void)up:(id)sender
{
    UIView *oneView = [self.view viewWithTag:1000];//取出Tag值为1000所对应的View
//   
//    CGRect r = oneView.frame;
//    r.size.width += 5;
//    r.size.height += 5;
    CGRect rect =CGRectInset(oneView.frame, -10, -10);
 //CGRect rect =CGRectInset(oneView.frame, 10, 10);//缩小
    oneView.frame = rect;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值