2012-08-01 17 views
3

在我的應用程序中,我想使滾動視圖的UIButton滑塊,其中當我們滾動按鈕的uiscrollview然後按鈕將位於中心請參閱這些應用程序的第一個屏幕sot http://itunes.apple.com/au/app/id422249255?mt=8如何我能做到這一點,我可以用什麼方法它目前我使用的UIScrollView如何使iPhone中的UIButton垂直的粉絲菜單

這些委託方法
-(void)scrollViewDidScroll:(UIScrollView *)aScrollView 
{ 


} 

(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 
{ 

} 

(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)aScrollView 
{ 

} 

回答

1

做到這一點:

在.m文件的頭部添加這些

#define viewWidth 40 //button width 
#define viewHeight 30 //button height 

#define viewOffsetX 5 //button left ie X 
#define viewOffsetY 5 //button right ie Y 

#define viewXspace 15 //button from top X space 
#define ViewYspace 5 //button from bottom 

你有按鈕的圖像陣列添加它們即arrBtnImages

現在,使用這些方法在你的滾動視圖即scView在viewDidLoad方法

- (void)loadBtnInSlider 
{ 
int row = 1; 
int col = [arrBtnImages count]/row; 

if ([mut_arrImages count] % col != 0 ) { 
    col++; 
} 

int index = 0; 
for (int i=0; i < row ; i++) 
{ 

    CGRect frame; 
    frame.size = CGSizeMake(viewWidth, viewHeight); 
    frame.origin.y = (i * viewHeight) + (i * ViewYspace) + viewOffsetY; 

    for (int j= 0; j < col && index < [mut_arrImages count]; j++) { 

     CGRect frame; 
     frame.size = CGSizeMake(viewWidth, viewHeight); 
     frame.origin.x = (j * viewWidth) + (j * viewXspace) + viewOffsetX; 
     frame.origin.y = viewOffsetY; 

     UIButton *btn = [[UIButton alloc]initWithFrame:frame]; 
     [btn setTag:j]; 
     [btn addTarget:self action:@selector(btnSelector:) forControlEvents:UIControlEventTouchUpInside]; 
     [btn setUserInteractionEnabled:YES]; 
     [btn setImage:[UIImage imageNamed:[arrBtnImages objectAtIndex:j]] forState:UIControlStateNormal]; 

     index++; 
     [scView addSubview:btn]; 
     [btn release]; 
    } 
} 
[scView setContentSize:CGSizeMake(col * (viewWidth+ViewYspace)+viewOffsetY,scView.frame.size.height)]; 
} 

使用此方法vieDidLoad這樣加載按鈕:

[self loadBtnInSlider]; 

現在添加下面選擇方法按鈕.h文件中,它會是這樣

-(void)btnSelector:(id)sender 
{ 
    UIButton *btnSelected = sender; 
    switch(btnSelected.tag) 
    { 
     // add case as much u have button 
     case 0: 
     //first button called 
     break; 

     case 1: 
     //second button called 
     break; 
     :: 
     :: 
    } 
}