当前位置:编程学习 > wap >>

iOS 圆形旋转托盘

 
效果图:
 
DJItemBtn.h
 
[plain] 
//  
//  DJItemBtn.h  
//  DjRotateMenuForiOS  
//  
//  Created by 杜甲 on 13-9-25.  
//  Copyright (c) 2013年 杜甲. All rights reserved.  
//  
  
#import <UIKit/UIKit.h>  
#import <QuartzCore/QuartzCore.h>  
@protocol DJItemBtnDelegate <NSObject>  
@optional  
  
-(void)djItemMethod:(int)btnTag;  
@end  
@interface DJItemBtn : UIView  
{  
@public  
   // id<DJItemBtnDelegate>delegate;  
}  
  
@property (retain,nonatomic)    id<DJItemBtnDelegate>delegate;  
      
  
  
@end  
 
DJItemBtn.m
 
[plain]  
//  
//  DJItemBtn.m  
//  DjRotateMenuForiOS  
//  
//  Created by 杜甲 on 13-9-25.  
//  Copyright (c) 2013年 杜甲. All rights reserved.  
//  
  
#import "DJItemBtn.h"  
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180  
  
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f)  
  
  
@implementation DJItemBtn  
  
- (id)initWithFrame:(CGRect)frame  
{  
    self = [super initWithFrame:frame];  
    if (self) {  
       self.backgroundColor = [UIColor greenColor];  
         
        self.layer.anchorPoint = CGPointMake(0, 0.5);  
         
   
        UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xiaonan1.jpg"]];  
        NSLog(@"aaaaaframe.size.width = %f",frame.size.width);  
        imageView.frame = CGRectMake(frame.size.width / 2, 0, 50, 25);  
          
        [self addSubview:imageView];  
        imageView.userInteractionEnabled = true;  
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickBtn)];  
        [imageView addGestureRecognizer:tap];  
  
          
          
    }  
    return self;  
}  
-(void)clickBtn  
{  
    [[NSNotificationCenter defaultCenter] postNotificationName:@"calculateDegress" object:nil];  
      
    [_delegate djItemMethod:self.tag];  
    NSLog(@"%d",self.tag);  
      
}  
  
  
  
  
@end  
 
DJRotateView.h
 
[plain] 
//  
//  DJRotateView.h  
//  DjRotateMenuForiOS  
//  
//  Created by 杜甲 on 13-9-25.  
//  Copyright (c) 2013年 杜甲. All rights reserved.  
//  
  
#import <UIKit/UIKit.h>  
#import "DJItemBtn.h"  
@interface DJRotateView : UIView  
  
-(id)initWithView:(CGRect)frame addtarget:(id)delegate;  
  
@end  
 
DJRotateView.m
 
[cpp]  
//  
//  DJRotateView.m  
//  DjRotateMenuForiOS  
//  
//  Created by 杜甲 on 13-9-25.  
//  Copyright (c) 2013年 杜甲. All rights reserved.  
//  
  
#import "DJRotateView.h"  
  
  
#define CC_DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) * 0.01745329252f) // PI / 180  
  
#define CC_RADIANS_TO_DEGREES(__ANGLE__) ((__ANGLE__) * 57.29577951f)  
  
  
  
@implementation DJRotateView  
-(id)initWithView:(CGRect)frame addtarget:(id)delegate  
{  
    self = [super initWithFrame:frame];  
    if (self) {  
        // Initialization code  
          
        //self.backgroundColor = [UIColor redColor];  
        float segment = 7.0;  
        double degree = 360 / segment;  
        float rotate =  CC_DEGREES_TO_RADIANS(degree);  
         NSLog(@"frame.size.width = %f",degree);  
        for (float i = 1.0; i <= 7.0; i++) {  
            DJItemBtn* djItemBtn = [[DJItemBtn alloc] initWithFrame:CGRectMake(frame.size.width / 2  - 50, frame.size.height / 2 * 0.87, 100, 25)];  
            djItemBtn.delegate = delegate;  
            [djItemBtn setTag:i];  
              
            djItemBtn.layer.transform = CATransform3DMakeRotation(rotate * (float)i , 0, 0, 1);  
            NSLog(@"rotate *i = %f",180.000 - degree *i);  
            NSLog(@"degree * i = %f",degree * i);  
            [self addSubview:djItemBtn];    
        }  
    }  
    return self;  
}  
//-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event  
//{  
//    return YES;  
//}  
  
//-(void)setRotate:(float)degress  
//{  
//    float rotate = CC_DEGREES_TO_RADIANS(degress);  
//    CGAffineTransform transform = self.djrotateView.transform;  
//    transform = CGAffineTransformRotate(transform, rotate);  
//  
补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,