zoukankan      html  css  js  c++  java
  • view沿着某一点旋转

    #import "JKZhuanPanTopBtnsView.h"

    CGFloat const topBtnsHeight = 400.0f;

    @interface JKZhuanPanTopBtnsView ()

    /**<#condition#>*/

    @property (nonatomic,strong)UIView * tempView;

    @property (nonatomic,assign) float angle;

    @end

    @implementation JKZhuanPanTopBtnsView

    CGAffineTransform  GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle)

    {

        x = x - centerX; //计算(x,y)从(0,0)为原点的坐标系变换到(CenterX ,CenterY)为原点的坐标系下的坐标

        y = y - centerY; //(0,0)坐标系的右横轴、下竖轴是正轴,(CenterX,CenterY)坐标系的正轴也一样

        

        CGAffineTransform  trans = CGAffineTransformMakeTranslation(x, y);

        trans = CGAffineTransformRotate(trans,angle);

        trans = CGAffineTransformTranslate(trans,-x, -y);

        return trans;

    }

    - (instancetype)initWithFrame:(CGRect)frame {

        if (self == [super initWithFrame:frame]) {

            self.backgroundColor = [UIColor redColor];

            

            

            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0 , 50, 50)];

            view.center = self.center;

            view.backgroundColor = [UIColor greenColor];

            [self addSubview:view];

            self.tempView = view;

            

            self.angle = 45.0/180.0*M_PI;

            

           

        }

        return self;

    }

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

        float centerX = self.tempView.bounds.size.width/2;

        float centerY = self.tempView.bounds.size.height/2;

        

    //    float centerX = self.bounds.size.width/2;

    //    float centerY = self.bounds.size.height/2;

        

    //    float x = self.tempView.bounds.size.width/2;

    //    float y = self.tempView.bounds.size.height;

            float x = 50;

            float y = 50;

        

        

        CGAffineTransform trans = GetCGAffineTransformRotateAroundPoint(centerX,centerY ,x ,y ,self.angle);

        

        self.angle += 45.0/180.0*M_PI;

        

        self.tempView.transform = CGAffineTransformIdentity;

        self.tempView.transform = trans;

    }

    /*

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect {

        // Drawing code

    }

    */

    @end

  • 相关阅读:
    sql语句中where后边的哪些条件会使索引失效 SQL语句优化
    jvm 判断对象死亡
    mysql数据库优化概述详解
    java集合框架详解
    jvm 图形化工具之jconsole
    java io框架详解
    多台Linux之间文件共享
    二 redis的安装启动
    jvm 线上命令工具
    java 线程6种状态的转换
  • 原文地址:https://www.cnblogs.com/Jackie-subDai/p/9336094.html
Copyright © 2011-2022 走看看