Objective c 为什么我的UIPickerView没有像它应该的那样动画化?

Objective c 为什么我的UIPickerView没有像它应该的那样动画化?,objective-c,xcode,animation,uipickerview,Objective C,Xcode,Animation,Uipickerview,这基本上就像吃角子老虎机一样,非常基本,但我遇到的问题是,当你点击旋转按钮时,组件的移动并没有动画,即使我给动画参数发送了一个YES BOOL。我不知道我做错了什么,任何帮助都将不胜感激 尼克 ps在此处下载整个项目: // //CustomPickerViewController.m //采摘者 // //由Nicholas Iannone于2010年1月29日创作。 //版权所有2010苹果公司。保留所有权利。 // #导入“CustomPickerViewController.h” @Cu

这基本上就像吃角子老虎机一样,非常基本,但我遇到的问题是,当你点击旋转按钮时,组件的移动并没有动画,即使我给动画参数发送了一个YES BOOL。我不知道我做错了什么,任何帮助都将不胜感激

尼克

ps在此处下载整个项目:

//
//CustomPickerViewController.m
//采摘者
//
//由Nicholas Iannone于2010年1月29日创作。
//版权所有2010苹果公司。保留所有权利。
//
#导入“CustomPickerViewController.h”
@CustomPickerViewController的实现
@合成column1、column2、column3、column4、column5、picker、winLabel;
-(iAction)自旋:(id)发送方{
NSLog(“甚至到了这里”);
布尔温=否;
int numInRow=1;
int lastVal=-1;
对于(int i=0;1<5;i++){
int newValue=random()%[self.column1 count];
if(newValue==lastVal){
NSLog(“甚至到了这里”);
numInRow++;
}
其他的
numInRow=1;
lastVal=新值;
[picker selectRow:newValue不完整项:i动画:是];
[选择器重新加载组件:i];
如果(numInRow>=3)
赢=是;
NSLog(“甚至到了这里”);
}
如果(赢)
winLabel.text=@“获胜者!”;
否则{
winLabel.text=@;
NSLog(“甚至到了这里”);
}
}
/*
//指定的初始值设定项。如果以编程方式创建控制器并希望执行不适用于viewDidLoad的自定义,请重写。
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil{
if(self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]){
//自定义初始化
}
回归自我;
}
*/
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
UIImage*seven=[UIImage ImageName:@“seven.png”];
UIImage*bar=[UIImage ImageName:@“bar.png”];
UIImage*crown=[UIImage ImageName:@“crown.png”];
UIImage*cherry=[UIImage ImageName:@“cherry.png”];
UIImage*lemon=[UIImage ImageName:@“lemon.png”];
UIImage*apple=[UIImage ImageName:@“apple.png”];

对于(int i=1;i它可能不是动画,因为您在选择带有动画的行后立即执行
[picker reloadComponent:i]
。重新加载可能会导致任何动画停止,并且不应该是必需的,因为您实际上没有更改picker的内容。

它可能不是动画,因为您执行
[选择器重新加载组件:i]
在选择带有动画的行后立即执行。重新加载可能会导致任何动画停止,并且不应该是必需的,因为您实际上没有更改选择器的内容。

我返回并将我的代码与该项目所列的书进行了比较,我注意到我的代码将按预期执行(带有动画)如果我要构建一个3.1.2 sdk和iphone sim卡,那么新xcode中的某些东西会影响动画效果,至少看起来是这样。

我回去将我的代码与该项目所列的书进行了比较,我注意到我的代码会按预期效果运行(带有动画)如果我要内置3.1.2 sdk和iphone sim卡,那么新xcode中的某些内容会影响动画效果,至少看起来是这样。

很抱歉,指向该项目的第一个链接是一个旧版本,但不起作用,而那里的新链接起作用。很抱歉,指向该项目的第一个链接是一个旧版本,不起作用,那里的新链接起作用。我扔掉它,还有其他想法吗?可能是笔尖上的东西吗?我扔掉了它,还有其他想法吗?可能是笔尖上的东西吗?我有同样的问题。在iOS4+或iOS5+中,UIPickerView的编程动画变得非常突然,不像你得到的平滑减速那样平滑手动轻弹UIPickerView时。有任何建议吗?我也有同样的问题。在iOS4+或iOS5+中,UIPickerView的编程动画已更改为非常突然,而不像手动轻弹UIPickerView时的平滑减速。有任何建议吗?
  //
       //  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