2010-02-01 47 views
1

所以这基本上像一个老虎机类型的东西,非常基本的,但我的问题是,当你点击旋转按钮组件的移动不动画,即使我已经发送动画参数YES BOOL。我不知道我做错了什么,任何帮助将不胜感激。为什么我的UIPickerView不像它应该是动画?

尼克

PS在这里下载整个项目:http://files.me.com/knyck2/dcca9y

// 
     // CustomPickerViewController.m 
    // Pickers 
    // 
    // Created by Nicholas Iannone on 1/29/10. 
    // Copyright 2010 Apple Inc. All rights reserved. 
    // 

    #import "CustomPickerViewController.h" 


    @implementation CustomPickerViewController 

    @synthesize column1, column2, column3, column4, column5, picker, winLabel; 

    -(IBAction) spin : (id) sender { 

NSLog(@"even got here"); 

BOOL win = NO; 

int numInRow = 1; 

int lastVal = -1; 

for (int i = 0; 1 < 5; i++) { 
int newValue = random() % [self.column1 count]; 

if (newValue == lastVal) { 
    NSLog(@"even got here"); 

numInRow++; 
} 
else 
    numInRow = 1; 

    lastVal = newValue; 
[picker selectRow:newValue inComponent:i animated:YES]; 
[picker reloadComponent:i]; 
if (numInRow >= 3) 
    win = YES; 

NSLog(@"even got here"); 

} 

if (win) 
winLabel.text = @"winner!"; 

      else { 
winLabel.text = @""; 
      NSLog(@"even got here"); 
      } 

    } 

    /* 
    // The designated initializer. Override if you create the controller  programmatically    and want to perform customization that is not appropriate  for viewDidLoad. 
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
// Custom initialization 
} 
return self; 
    } 
    */ 


    // Implement viewDidLoad to do additional setup after loading the view, typically from   a nib. 
    - (void)viewDidLoad { 
UIImage *seven = [UIImage imageNamed:@"seven.png"]; 
UIImage *bar = [UIImage imageNamed:@"bar.png"]; 
UIImage *crown = [UIImage imageNamed:@"crown.png"]; 
UIImage *cherry = [UIImage imageNamed:@"cherry.png"]; 
UIImage *lemon = [UIImage imageNamed:@"lemon.png"]; 
UIImage *apple = [UIImage imageNamed:@"apple.png"]; 

for (int i = 1; i <= 5 ; i++) { 
    UIImageView *sevenView = [[UIImageView alloc] initWithImage: seven]; 
    UIImageView *barView = [[UIImageView alloc] initWithImage: bar]; 
    UIImageView *crownView = [[UIImageView alloc] initWithImage: crown]; 
    UIImageView *cherryView = [[UIImageView alloc] initWithImage:  cherry]; 
    UIImageView *lemonView = [[UIImageView alloc] initWithImage: lemon]; 
    UIImageView *appleView = [[UIImageView alloc] initWithImage: apple]; 


    NSArray *imageViewArray = [[NSArray alloc] initWithObjects:  sevenView, barView, crownView, cherryView, lemonView, appleView, nil]; 
    NSString *fieldName =[[NSString alloc] initWithFormat:@"column%d",  i]; 
    [self setValue:imageViewArray forKey:fieldName]; 
    [fieldName release]; 
    [imageViewArray release]; 

    [sevenView release]; 
    [crownView release]; 
    [barView release]; 
    [cherryView release]; 
    [lemonView release]; 
    [appleView release]; 

    } 

srandom(time(NULL)); 
[super viewDidLoad]; 
    } 



    /* 
    // Override to allow orientations other than the default portrait orientation. 
    -  (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
    */ 

    - (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
    } 

    - (void)viewDidUnload { 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
    } 


    - (void)dealloc { 
[picker release]; 
[winLabel release]; 
[column1 release]; 
[column2 release]; 
[column3 release]; 
[column4 release]; 
[column5 release]; 


[super dealloc]; 
    } 


    #pragma mark - 
    #pragma mark Picker Data Source Methods 

    -(NSInteger) numberOfComponentsInPickerView: (UIPickerView *) pickerView { 

return 5; 
    } 


    -(NSInteger) pickerView: (UIPickerView *) pickerView numberOfRowsInComponent:   (NSInteger) component { 

return [self.column1 count]; 

    } 

    #pragma mark Picker Delegate Methods 

    -(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger) component reusingView : (UIView *)view { 

NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d", component + 1]; 
NSArray *array = [self valueForKey:arrayName]; 
NSLog(@"got here yo"); 
return [array objectAtIndex: row]; 
NSLog(@"holyshit"); 


    } 

    @end 
+0

对不起,该项目的第一个链接是旧版本,没有工作,新的链接。 – nickthedude 2010-02-01 21:42:57

回答

1

我回过头来把我的代码和这个项目列出的书进行了比较,并且我注意到如果我要构建到3.1.2 sdk和iphone sim中,我的代码将按预期执行(使用动画)。因此,新的xcode中的某些东西正在扫描动画,至少它看起来就是这样。

+0

我有同样的问题。无论是在iOS4 +还是iOS5 +中,UIPickerView的编程动画都会变得非常突兀,而不是像手动轻拂UIPickerView时获得的平滑减速那样平滑。任何建议任何人? – Bogatyr 2013-04-04 11:25:32

0

这可能不是动画,因为你选择用动画的行权后做[picker reloadComponent:i]。重新加载可能会导致任何动画停止,并且不应该有必要,因为您实际上并未更改选取器的内容。

+0

我摆脱了它,仍然是一样的,任何其他的想法?这可能是笔尖的东西吗? – nickthedude 2010-02-01 21:49:24

相关问题