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

  • 相关阅读:
    JavaScipt
    实例应用,做了一个网页
    css 层叠式样式表(3)
    css 层叠式样式表(2)
    css 层叠式样式表(1)
    HTML 框架
    .NET回归 HTML----表单元素(1)和一些常用的标记
    .NET回归 HTML----超文本标记语言(暂时无图)
    排序算法: 选择排序法
    排序算法:快速排序法
  • 原文地址:https://www.cnblogs.com/hanjun/p/2731741.html
Copyright © 2011-2022 走看看