菱形开合的实现 IOS
实现的原理: 利用了自动布局和形变
核心代码块:
@implementation JHMainView
{
UILabel *label1,*label2,*label3,*label4;
UIButton *btn;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 120, 120, 120)];
btn.transform = CGAffineTransformRotate(btn.transform, M_PI_4);
[btn addTarget:self action:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
btn.autoresizesSubviews = YES;
//btn.backgroundColor = [UIColor cyanColor];
label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
label1.backgroundColor = [UIColor orangeColor];
label2 = [[UILabel alloc]initWithFrame:CGRectMake(btn.bounds.size.width/2, 0, 60, 60)];
label2.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
label2.backgroundColor = [UIColor blackColor];
label3 = [[UILabel alloc]initWithFrame:CGRectMake(0, btn.bounds.size.height/2, 60, 60)];
label3.backgroundColor = [UIColor blueColor];
label3.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
label4 = [[UILabel alloc]initWithFrame:CGRectMake(btn.bounds.size.width/2, btn.bounds.size.height/2, 60, 60)];
label4.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
label4.backgroundColor = [UIColor purpleColor];
[btn addSubview:label1];
[btn addSubview:label2];
[btn addSubview:label3];
[btn addSubview:label4];
[self addSubview:btn];
}
return self;
}
- (void)btnClick:(UIButton *)sender
{
static int i=1 ;
btn.center = btn.center;
if(i%2)
{
btn.bounds = CGRectMake(0, 0, 180, 180);
}
else
{
btn.bounds = CGRectMake(0, 0, 120, 120);
}
i++;
}
@end
菱形开合的实现 IOS的更多相关文章
- ios开发之OC基础-ios开发学习路线图
本系列的文章主要来自于个人在学习前锋教育-欧阳坚老师的iOS开发教程之OC语言教学视频所做的笔记,边看视频,边记录课程知识点.建议大家先过一遍视频,在看视频的过程中记录知识点关键字,把把握重点,然后再 ...
- android qq开合表
qq悬浮列表功能暂未实现 main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr ...
- 轻松实现Android,iOS的一个手势动画效果
先来看效果 这是iOS下的效果,android下完全一致.通过do_GestureView组件和do_Animation组件,deviceone能很容易实现复杂的跨平台纯原生动画效果,这个示例就是通过 ...
- ToolBar和DrawerLayout的使用实现侧拉栏抽屉的开闭
1.如图可以看到textColorPrimary,colorPrimary,colorPrimaryDark,navigationBarColor等颜色属性代表的相应位置,如下图 2.具体属性在res ...
- XE6移动开发环境搭建之IOS篇(9):配置XE6的IOS SDK(有图有真相)
网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 1.开启PAServ ...
- 直接拿来用!最火的iOS开源项目
1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...
- (转)直接拿来用!最火的iOS开源项目(二)
“每一次的改变总意味着新的开始.”这句话用在iOS上可谓是再合适不过的了.GitHub上的iOS开源项目数不胜数,iOS每一次的改变,总会引发iOS开源项目的演变,从iOS 1.x到如今的iOS 7, ...
- IOS常用开源库
转自:http://www.csdn.net/article/2013-06-18/2815806-GitHub-iOS-open-source-projects-two/1 1. AFNetwork ...
- iOS 操作系统架构
Mac OS 和 iOS 操作系统架构 做iOS开发已经半年多了,但是感觉对iOS开发的理解却还只停留在表面,昨天刚把两个项目结了,今天打算学了一下iOS系统的架构,以便于更好的理解和开发. 首先看一 ...
随机推荐
- Hibernate由model类自动同步数据库表结构
在开发中遇到了个问题,每次测试数据库增加表结构的时候,本地pull下最新代码导致启动报错,上网搜了快速解决办法---->hibernate 配置属性中,hibernate.hbm2ddl.aut ...
- day16<集合框架+>
集合框架(去除ArrayList中重复字符串元素方式) 集合框架(去除ArrayList中重复自定义对象元素) 集合框架(LinkedList的特有功能) 集合框架(栈和队列数据结构) 集合框架(用L ...
- 使用jsonp来实现跨域请求
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 如何面试 PHP 工程师?
1,解决问题的能力和掌握的知识,看你招聘的目的而决定其二者的平衡.了解流体力学的确会对通下水道有很大帮助,但流体力学专家未必都会疏通下水道. 2,创造力,一个没有自己作品的程序员不是好程序员.编程跟写 ...
- vue.js项目构建
这里构建的vue.js项目依赖node服务器运行. 项目搭建完整步骤: 安装node.js ,转至nodeJs网站http://nodejs.cn/ 下载nodeJs进行安装. 安装完毕检查nodeJ ...
- Find 找规律,递推
Find Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus P ...
- E. Fish (概率DP)
E. Fish time limit per test 3 seconds memory limit per test 128 megabytes input standard input outpu ...
- Android01-布局篇
在Android中,共有五种布局方式,分别是:LinearLayout(线性布局),FrameLayout(帧布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局) ...
- vue + ajax + php 接口的使用小接
vue + ajax + php 接口的使用小接 前端代码: (获取用户信息,并渲染页面) userinfor.html <!DOCTYPE html> <html lang=&qu ...
- WebApi实现验证授权Token,WebApi生成文档等
using System; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Security; ...