实现的原理: 利用了自动布局和形变

核心代码块:

@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的更多相关文章

  1. ios开发之OC基础-ios开发学习路线图

    本系列的文章主要来自于个人在学习前锋教育-欧阳坚老师的iOS开发教程之OC语言教学视频所做的笔记,边看视频,边记录课程知识点.建议大家先过一遍视频,在看视频的过程中记录知识点关键字,把把握重点,然后再 ...

  2. android qq开合表

    qq悬浮列表功能暂未实现 main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr ...

  3. 轻松实现Android,iOS的一个手势动画效果

    先来看效果 这是iOS下的效果,android下完全一致.通过do_GestureView组件和do_Animation组件,deviceone能很容易实现复杂的跨平台纯原生动画效果,这个示例就是通过 ...

  4. ToolBar和DrawerLayout的使用实现侧拉栏抽屉的开闭

    1.如图可以看到textColorPrimary,colorPrimary,colorPrimaryDark,navigationBarColor等颜色属性代表的相应位置,如下图 2.具体属性在res ...

  5. XE6移动开发环境搭建之IOS篇(9):配置XE6的IOS SDK(有图有真相)

    网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 1.开启PAServ ...

  6. 直接拿来用!最火的iOS开源项目

    1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...

  7. (转)直接拿来用!最火的iOS开源项目(二)

    “每一次的改变总意味着新的开始.”这句话用在iOS上可谓是再合适不过的了.GitHub上的iOS开源项目数不胜数,iOS每一次的改变,总会引发iOS开源项目的演变,从iOS 1.x到如今的iOS 7, ...

  8. IOS常用开源库

    转自:http://www.csdn.net/article/2013-06-18/2815806-GitHub-iOS-open-source-projects-two/1 1. AFNetwork ...

  9. iOS 操作系统架构

    Mac OS 和 iOS 操作系统架构 做iOS开发已经半年多了,但是感觉对iOS开发的理解却还只停留在表面,昨天刚把两个项目结了,今天打算学了一下iOS系统的架构,以便于更好的理解和开发. 首先看一 ...

随机推荐

  1. mybatis-mapper文件介绍

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...

  2. 【Spring源码深度解析系列 】Spring整体架构

    一.Spring的整体架构和模块 二.模块分类: 1.Core Container Core Container包含有Core .Beans.Context.和Expression  Language ...

  3. 九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <init> 严重: The ResourceConfig instance does not contain any root resource classes.

    Tomcat启动错误:九月 26, 2017 10:18:14 上午 com.sun.jersey.server.impl.application.RootResourceUriRules <i ...

  4. Mysql 基于 Amoeba 的 读写分离

    首先说明一下amoeba 跟 MySQL proxy在读写分离的使用上面的区别: 在MySQL proxy 6.0版本 上面如果想要读写分离并且 读集群.写集群 机器比较多情况下,用mysql pro ...

  5. Spring 学习——基于Spring WebSocket 和STOMP实现简单的聊天功能

    本篇主要讲解如何使用Spring websocket 和STOMP搭建一个简单的聊天功能项目,里面使用到的技术,如websocket和STOMP等会简单介绍,不会太深,如果对相关介绍不是很了解的,请自 ...

  6. java集合系列——List集合之Stack介绍(五)

    1.Stack的简介 Stack 类表示后进先出(LIFO)的对象堆栈.它通过五个操作对类 Vector 进行了扩展 ,允许将向量视为堆栈.它提供了通常的 push 和 pop 操作,以及取堆栈顶点的 ...

  7. java集合系列——List集合之Vector介绍(四)

    1. Vector的简介 JDK1.7.0_79版本 Vector 类可以实现可增长的对象数组.与数组一样,它包含可以使用整数索引进行访问的组件.但是,Vector 的大小可以根据需要增大或缩小,以适 ...

  8. TCHAR

    定义 TCHAR :通过define 定义的字符串宏 因为C++支持两种字符串:常规的ANSI编码 (使用""包裹).Unicode编码(使用L" "包裹).因 ...

  9. Huge Mission

    Huge Mission Problem Description Oaiei is busy working with his graduation design recently. If he ca ...

  10. JavaWeb(一)Servlet中的request与response

    一.HttpServletRequest概述 1.1.HttpServletRequest简介 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP ...