2012-06-08 51 views
1

我寫在viewDidLoad方法動畫概念我寫:當我點擊按鈕時,如何移動到下一個屏幕?

scaleFactor=2; 
    angle=180; 
    CGRect frame = CGRectMake(10,10,45,45); 
    UIView *box; 
    box=[[UIView alloc] initWithFrame:frame]; 
    box.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"images673.png"]; 
    [self.view addSubView:box]; 

//該代碼可用於一個對象在屏幕上的觸摸事件 //對於對象移動我寫的方法,該方法如下所示:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
     { 
     UITouch *touch=[touches anyObject]; 
     CGPoint location=[touch locationInView:self.view]; 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDelegate:self]; 
     [UICiew setAnimationDuration:1]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
     box.center=location; 
     [UIView commitAnimations]; 
     } 

//然後,現在我寫了具有導航到另一個類文件//一般導航原理,我寫

-(IBAction)settings:(id)sender 
{ 
aScreen *abc=[[aScreen alloc]init]; 
[self.navigationController pushViewController:abc animated:YES]; 
[abc release]; 
} 
按鈕

現在對象正在移動,我在屏幕上點擊,但是當我點擊按鈕時,圖像沒有放在按鈕的頂部。請問怎麼辦。請幫助我。我拍了一張圖片,然後我製作了一些動畫讓它移動到我點擊屏幕的地方。但同時,我拿了一個按鈕,然後在viewcontroller中寫了一個按鈕事件動作。當我點擊按鈕時,圖像不會移動到按鈕上。

我想要做的是如果我點擊按鈕,圖像必須放到按鈕上,它應該顯示下一個視圖控制器。任何人都可以幫助我這麼做嗎?當我點擊按鈕時圖像掉落時如何移動到下一個屏幕?

+0

方法的一些身體幫我如何進行進一步請 – Ratnakar

+0

您能不能告訴我們任何代碼跟隨你做得更好?你是什​​麼意思掉到按鈕上?你的意思是它只是放在按鈕的頂部或成爲按鈕的一部分? – glogic

+0

它只是放在按鈕的頂部,圖像必須消失,然後按鈕事件動作必須被觸發 – Ratnakar

回答

0

林不知道我沒有看到你的代碼完全理解這個問題,但你不能做這樣的事情嗎?

-(ibaction)buttonevent:(id)sender{ 
cgrect frame = image.frame; 
frame.origin.x = button.frame.x; 
frame.origin.y = button.frame.y; 
image.frame = frame; 
image.alpha = 0; 

[self pushviewcontroller:newViewcontroller animated:yes]; 
} 
+0

新堆棧溢出請原諒,請有人編輯我的問題到一個特定的方式 – Ratnakar

+0

看到glogic上面我貼了代碼。我想你不明白。請耐心地檢查一下。 – Ratnakar

+0

但是,當我編寫我在IBAction方法中使用viewDidLoad方法編寫的代碼時,圖像被點擊,但無限的圖像正在顯示,而且屏幕導航沒有完成。該怎麼做。在這種情況下,我做錯了什麼 – Ratnakar

0

嗨試試這段代碼我已經檢查。這是爲我工作,當您檢查按鈕,您拖動相交,則圖像火的地方移動到下一個屏幕

// Handles the continuation of a touch. 
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
//NSLog(@"touchesMoved"); 
UITouch *touch = [touches anyObject]; 
if ([touch view] == mKey) { 

    NSUInteger touchCount = 0; 

    // Enumerates through all touch objects 
    for (UITouch *touch in touches) { 
     // Send to the dispatch method, which will make sure the appropriate subview is acted upon 
     [self dispatchTouchEvent:[touch view] toPosition:[touch locationInView:self.view]]; 
     touchCount++; 
    } 

} 



} 

// Checks to see which view, or views, the point is in and then sets the center of each moved view to the new postion. 
// If views are directly on top of each other, they move together. 
-(void)dispatchTouchEvent:(UIView *)theView toPosition:(CGPoint)position 
{ 

// Check to see which view, or views, the point is in and then move to that position. 

if (CGRectContainsPoint([mKey frame], position)) 
{ 
    NSLog(@"touchesMoved"); 
    mKey.center = position; 

} 


if(CGRectIntersectsRect([mKey frame], [inVisible frame]) && k==0) 
{ 
    self.view.userInteractionEnabled=NO; 
    NSLog(@"thirdPiew frame"); 

    [inVisible setHighlighted:YES]; 
    [inVisible setShowsTouchWhenHighlighted:YES]; 
    k=1; 
    [self performSelector:@selector(modalPresentationButtonPressed:)];  

} 
} 
相關問題