• 运动的点,,


    //

    //  CommonUserMenu.m

    //  Zhaocailing

    //

    //  Created by zhaocailing on 13-10-17.

    //  Copyright (c) 2013 totem. All rights reserved.

    //

     

    #import "CommonUserMenu.h"

    #import "Constant.h"

    #import "DataModel.h"

     

    @implementation CommonUserMenu

     

    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

            [selfdoAdditionalInit];

        }

        returnself;

    }

     

    - (void)awakeFromNib

    {

        [selfdoAdditionalInit];

    }

     

    - (void)doAdditionalInit

    {

        CGRect frame = self.frame;

        frame.size = CGSizeMake(46, 44);

        self.frame = frame;

        self.backgroundColor = [UIColorclearColor];

        self.iconButton = [[UIButtonalloc] initWithFrame:CGRectMake(0, 0, 44, 44)];

        [self addSubview:self.iconButton];

        self.iconButton.backgroundColor = [UIColorclearColor];

        self.dotImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(31, 1, 15, 17)];

        [selfaddSubview:self.dotImageView];

        self.dotImageView.image = [UIImageimageNamed:@"common_user_icon_dot.png"];

        self.gender = 1;

        self.showDot = NO;

        self.recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(paned:)];

        [selfaddGestureRecognizer:self.recognizer];

    }

     

    - (void)paned:(UIPanGestureRecognizer*)recog

    {

        switch (recog.state) {

            caseUIGestureRecognizerStateBegan:

                lastCenter = self.frame.origin;

                break;

            caseUIGestureRecognizerStateChanged:

            {

                CGRect frame = self.frame;

                CGPoint position = [recog translationInView:self];

                frame.origin.x = lastCenter.x + position.x;

                frame.origin.y = lastCenter.y + position.y;

                self.frame = frame;

                break;

            }

            caseUIGestureRecognizerStateEnded:

            {

                CGRect frame = self.frame;

                CGPoint volic = [recog velocityInView:self];

                //速度超过600,按照速度的方向放置按钮

                if (fabsf(volic.x) > 600) {

                    float aspect = volic.y/volic.x;

                    if (volic.x > 0) {

                        float yC = aspect * (self.superview.frame.size.width - frame.size.width - frame.origin.x);

                        frame.origin.y += yC;

                        frame.origin.x = self.superview.frame.size.width - frame.size.width;

                    }

                    else {

                        float yC = aspect * frame.origin.x;

                        frame.origin.y -= yC;

                        frame.origin.x = 0;

                    }

                }

                else {

                    if (self.center.x <= self.superview.frame.size.width/2) {

                        frame.origin.x = 0;

                    }

                    else if (self.center.x > self.superview.frame.size.width/2) {

                        frame.origin.x = self.superview.frame.size.width - frame.size.width;

                    }

                }

                if (frame.origin.y < 44) {

                    frame.origin.y = 44;

                }

                else if (frame.origin.y > self.superview.frame.size.height - frame.size.height - 30) {

                    frame.origin.y = self.superview.frame.size.height - frame.size.height - 30;

                }

                float duration = 0.25f * fabsf(self.center.x - self.superview.frame.size.width) / self.superview.frame.size.width * 2;

                duration = 0.14f;

                [UIViewanimateWithDuration:duration animations:^{

                    self.frame = frame;

                } completion:^(BOOL finished) {

                    lastCenter = self.frame.origin;

                }];

                break;

            }

            default:

                break;

        }

    }

     

    - (void)setGender:(int)gender

    {

        _gender = gender;

        if (_gender == 1) {

            [self.iconButtonsetImage:[UIImageimageNamed:@"common_user_icon_men.png"] forState:UIControlStateNormal];

        }

        else {

            [self.iconButtonsetImage:[UIImageimageNamed:@"common_user_icon_women.png"] forState:UIControlStateNormal];

        }

    }

     

    - (void)setShowDot:(BOOL)showDot

    {

        _showDot = showDot;

        self.dotImageView.hidden = !showDot;

    }

     

    /*

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

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect

    {

        // Drawing code

    }

    */

     

    @end

  • 相关阅读:
    JSON2 源代码
    C#冒泡排序详解
    SqlHelper 带详细中文注释
    js-cookie
    淘宝镜像(cnpm) 安装
    vue全局刷新
    webpack-npm安装-查看当前版本
    半环进度条
    Parameter 'name' implicitly has an 'any' type.
    vue3.0-如何切换路由-路由模式ts
  • 原文地址:https://www.cnblogs.com/guligei/p/3396353.html
Copyright © 2020-2023  润新知