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.运行,成功!

  • 相关阅读:
    Tomcat造成404
    ajax缺少@ResponseBody注解前台404,业务可以运行
    几种常见的Runtime Exception
    SQL注入通俗讲解
    MYSQL数据库导入大数据量sql文件失败的解决方案
    css选择器
    http端口
    基础算法之最大子列求和问题
    基础算法之链表逆序
    Prolog&Epilog
  • 原文地址:https://www.cnblogs.com/hanjun/p/2731741.html
Copyright © 2011-2022 走看看