然后我们来写:TypeSelectView
这个比较简单,我们只要只要每个TypeView的位置,然后作为自己的subview就好了
@interface TypeSelectView : UIView @property(nonatomic) BOOL bShown; @property(nonatomic, strong) TypeView* curSelectedView; -(id)initWithFrame:(CGRect)frame searchType:(int)type; @end
-(id)initWithFrame:(CGRect)frame searchType:(int)type
{
    self = [super initWithFrame:frame];
    if (self) {
        _bShown = NO;
        self.backgroundColor = [UIColor clearColor];
        CGRect rcBg = frame;
        rcBg.origin.y = 0.0f;
        rcBg.origin.x = 0.0f;
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:rcBg];
        bgImageView.image = [UIImage imageNamed:@"change_icon_bg.png"];
        [self addSubview:bgImageView];
        
        CGRect typeRc =CGRectMake(4.0f, 0.0f, TypeView_Width, TypeView_Height);
        for (int i = 0; i < 4; i++) {
            TypeView *curTypeView = [[TypeView alloc] initWithFrame:typeRc];
            curTypeView.typesView = self;
            curTypeView.typeId = i;
            if (i == type) {
                curTypeView.bSelected = YES;
                self.curSelectedView = curTypeView;
            }
            [self addSubview:curTypeView];
            
            if (i == 3) {
                typeRc.origin.x = 4.0f;
                typeRc.origin.y = 78.0f;
            }else {
                typeRc.origin.x += 314.0f/4;
            }
        }
    }
    
    return self;
}
    
@interface TopBarView : UIView -(void)layoutViews; @property(nonatomic,strong)TopBarControllerViewController* myViewController; @property(nonatomic)UIButton* button; @property(nonatomic)UITextField* textField; @property (nonatomic, strong) TypeSelectView *topTypesView; -(void)onclick; @end
-(void)layoutViews{
     self.clipsToBounds = YES;
    _topTypesView.bShown = NO;
    
    TypeSelectView* tmpType = [[TypeSelectView alloc] initWithFrame:[[HomePageUIManager sharedInstance]       searchTypesOriginFrame] searchType:0];
    _topTypesView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
    UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
    _topTypesView = tmpType;
    //这样写_topTypesView在这些view的后面
   [[MyViewController sharedInstance].view insertSubview:_topTypesView belowSubview:self];- (CGRect)searchTypesOriginFrame
{
	return CGRectMake(0.0f, 44.0f- 80.0f, 320.0f, 80.0f);
}- (CGRect)searchTypesShowFrame
{
	return CGRectMake(0.0f, 44.0f, 320.0f, 80.0f);
}
- (void)toShowTypesView {
    _topTypesView.frame = [[HomePageUIManager sharedInstance] searchTypesOriginFrame];
	[UIView beginAnimations:@"ShowTypes" context:NULL];
	[UIView setAnimationDuration:0.4f];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
	[UIView setAnimationBeginsFromCurrentState:YES];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	
    
	_topTypesView.bShown = YES;
	_topTypesView.frame = [[HomePageUIManager sharedInstance] searchTypesShowFrame];
	
	
    
    [UIView commitAnimations];
}- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
       <strong>// self.view.backgroundColor = [MyViewController RGBColorFromHexString:@"#eeeeee" alpha:1.0f];//特别注意不要加这句,如果加上会使MyViewController去执行viewdidload会导致程序崩溃</strong>
    }
    return self;
}
//单例的写法
+ (MyViewController *)sharedInstance
{
	static MyViewController *_sharedInstance = nil;
	if (_sharedInstance == nil)
		_sharedInstance = [[MyViewController alloc] initWithNibName:nil bundle:nil];
	return _sharedInstance;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    CGRect rcSearchBar = [[HomePageUIManager sharedInstance] searchBarViewFrame];
    TopBarView *tmpView = [[TopBarView alloc] initWithFrame:rcSearchBar];
    [tmpView layoutViews];
    [self.view addSubview:tmpView];
    
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320,2)];
    view.backgroundColor = [UIColor grayColor];
    [self.view addSubview:view];
    
}
IOS的一个带动画的多项选择的控件(二),布布扣,bubuko.com
原文地址:http://blog.csdn.net/baidu_nod/article/details/37886587