zoukankan      html  css  js  c++  java
  • 视图移动

    1.新建Empty Application

    command+n,添加一个oc文件(UIViewController),命名为:HomeViewController

    2.在HomeViewController.h中声明全局变量
    UIView *tView;

    3.在HomeViewController.m中:

    //创建View的函数
    -(void) loadView
    {
    [super loadView];
    //创建View
    //UIView *tView;
    tView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    tView.backgroundColor=[UIColor redColor];
    [self.view addSubview:tView];

    //创建按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(120, 300, 100, 30);

    [btn setTitle:@"移动" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(animate:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:btn];

    }

    - (void) animate:(id)sender
    {
    //添加动画
    [UIView beginAnimations:nil context:nil];//开始动画
    [UIView setAnimationDuration:0.75];//0.75s

    // //翻转效果1
    // [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
    // forView:tView
    // cache:YES];

    //翻转效果2
    if(tView.frame.origin.x==100)
    {
    tView.frame = CGRectMake(150, 150, 150, 150);
    return;
    }

    if(tView.frame.origin.x==150)
    {
    tView.frame = CGRectMake(100, 100, 100, 100);
    return;
    }

    [UIView commitAnimations]; //提交动画
    }

    4.运行,成功!

  • 相关阅读:
    在Twrp下删除面具模块
    Windows之批量创建用户、组部署
    H3C之HDLC实验部署
    Linux之防火墙部署
    H3C之Telnet实验部署
    win10 远程桌面 ubuntu
    VMware 虚拟机开机黑屏
    计算机存储单位换算
    TextCNN代码实践
    TextCNN论文解读
  • 原文地址:https://www.cnblogs.com/hanjun/p/2731741.html
Copyright © 2011-2022 走看看