2011-08-19 42 views
-2
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 300.0, 43.0, 43.0)]; 
    [imageView setBackgroundColor:[UIColor clearColor]]; 
    [imageView setImage:[UIImage imageNamed:@"test.png"]]; 
    [self.view addSubview:imageView]; 

[UIView setAnimationRepeatAutoreverses:YES]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView animateWithDuration: 0.2f 
        delay: 0.0f 
        options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState 
       animations: ^(void){[imageView setFrame:CGRectMake(0.0, 350.0, 43.0, 43.0)];} 
       completion: nil]; 


UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setFrame:CGRectMake(100, 0, 100, 30)]; 
[button setTitle:@"Button" forState:UIControlStateNormal]; 
[self.view addSubview:button]; 
+1

嗨,你有什麼問題。你能解釋清楚 – Satya

+0

我將上面的代碼添加到viewController,運行時,該按鈕不能被觸摸 – HunkSmile

+0

應用程序崩潰,而觸摸按鈕?你根本看不到按鈕? – EmptyStack

回答

0

嘗試修改您的animateWithDuration:見下文

[UIView animateWithDuration: 0.2f 
         delay: 0.0f 
         options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState 
        animations: ^(void){[imageView setFrame:CGRectMake(0.0, 350.0, 43.0, 43.0)];} 
        completion: nil]; 

在我的附加值UIViewAnimationOptionAllowUserInteraction

+0

謝謝。你是對的 – HunkSmile

0

做如下改變按鈕定義:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

你的方法應該是象下面這樣:

-(IBAction)buttonHandle:(id)sender 
{ 
} 

我希望這將是有益的。

+0

add UIViewAnimationOptionAllowUserInteraction – HunkSmile

0

的選項屬性。如果你不能夠觸摸按鈕(如果點擊不工作),然後

編寫代碼

[self.view bringSubviewToFront:button]; 

在方法結束時。

+0

感謝您的回答 – HunkSmile

0

我想你想對按鈕執行操作,所以試試這段代碼。

 UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [button setFrame:CGRectMake(100, 0, 100, 30)]; 
     [button setTitle:@"Button" forState:UIControlStateNormal]; 
    [button addTarget:self   action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside]; 

     [self.view addSubview:button]; 

-(IBAction)buttonPressed:(id)sender 
{ 
    //put code here you want to perform action on button 
} 
+0

添加UIViewAnimationOptionAllowUserInteraction,我已經完成 – HunkSmile