2011-05-08 14 views
23

से UITableviewCell स्थिति प्राप्त करें I uviewview और uitabbar पर एक आईफोन ऐप बेस बनाएं। टेबलव्यू के प्रत्येक सेल पर मेरे पास "पसंदीदा बटन में जोड़ें" है। जब मैंने इस बटन को दबाया, तो मैं टैब को अपनी स्थिति से "कूद" को टैबबार के पसंदीदा आइटम (इंस्टॉलस में डाउनलोड प्रभाव के समान) बनाना चाहता हूं"दृश्यमान" क्षेत्र या विंडो

यदि मैं शीर्ष 10 सेल पर हूं तो प्रभाव अच्छी तरह से काम करता है , लेकिन अगर मैं तालिका में स्क्रॉल करता हूं तो देखें प्रभाव अच्छा नहीं है क्योंकि प्रारंभ स्थिति यूटेबलव्यू आकार से गणना की जाती है।

दृश्य क्षेत्र से किसी सेल की स्थिति जानना संभव है। ?

उदाहरण: फोर्टेथ सेल स्थिति x: 0, y: 1600, w: 320, y: 50 है, मैं स्क्रीन के शीर्ष से स्थिति को uiview के शीर्ष से नहीं चाहता हूं, इसलिए इस x की तरह कुछ : 0, वाई: 230, डब्ल्यू: 320, वाई: 50

उत्तर

75

हाँ आप rectForRowAtIndexPath: का उपयोग कर सकते हैं, आपको बस अपनी पंक्ति के सूचकांक में प्रवेश करना होगा।

rectForRowAtIndexPath:

एक पंक्ति सूचकांक पथ से पहचान के लिए ड्राइंग क्षेत्र देता है।

...

संपादित

रूपांतरण:

CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath]; 
CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]]; 
+0

20 सेल RectForRowAtIndexPath के लिए मुझे x: 0, y: 1200 वापस लौटें और मैं दृश्य के शीर्ष से स्थिति चाहता हूं, (स्टेटस बार से) तो यह 20 और लगभग 367 (दृश्य का आकार) के बीच होना चाहिए – Mickael

+0

@ बेंजा मिनट Frolicher क्षमा करें, मैंने अपना जवाब अपडेट कर दिया है, रूपांतरण गायब था। –

+0

धन्यवाद निक, आपकी टिप्पणी में कोड अच्छी तरह से काम करते हैं! – Mickael

-1

तो यहाँ कोड मैं प्रयोग किया जाता है: (यह अनुकूलित किया जा सकता है मुझे यकीन है कि हूँ):

पहले अपने कस्टम सेल में NSindexPath ** संपत्ति जोड़ें।
* अपने tableview नियंत्रक में इस लागू: *

-(void)addCellToFavorisWithAnimation:(ResultSearchOffreCell*)cell{ 
/* Generate image from cell 
----------------------------------------------------------*/ 
UIGraphicsBeginImageContextWithOptions(cell.bounds.size, cell.opaque, [[UIScreen mainScreen] scale]); 
[cell.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

// Launch first animation (go to top-right) 
//----------------------------------------------------------*/ 
CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:cell.indexPath]; 
CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]]; 

cellAnimationContainer = [[UIImageView alloc] initWithFrame:rectInSuperview]; 

[cellAnimationContainer setFrame:CGRectMake(cellAnimationContainer.frame.origin.x, cellAnimationContainer.frame.origin.y+50 , cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)]; 

[cellAnimationContainer setImage:img]; 

AppDelegate_Shared *appDelegate = [UIApplication sharedApplication].delegate; 
[appDelegate.window addSubview:cellAnimationContainer]; 
[UIView beginAnimations:@"addFavorite-Step1" context:nil]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
[UIView setAnimationDuration:0.2]; 
[cellAnimationContainer setFrame:CGRectMake(20,cellAnimationContainer.frame.origin.y-10, cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)]; 
[cellAnimationContainer setAlpha:0.7]; 
[UIView commitAnimations]; 
} 
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ 


/* Launch second animation => go to favoris Tab and remove from self.view 
---------------------------------------------------------------------------*/ 
if([anim isEqual:@"addFavorite-Step1"]) 
{ 
    [UIView beginAnimations:@"addFavorite-Step2" context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationDelegate:self]; 
    [cellAnimationContainer setAlpha:0.4]; 
    [cellAnimationContainer setFrame:CGRectMake(150, 420, 20, 20)]; 
    [UIView commitAnimations]; 
} 
else if([anim isEqual:@"addFavorite-Step2"]) 
{ 
    [cellAnimationContainer removeFromSuperview]; 
    [cellAnimationContainer release];   
} 
} 
-1

हाँ इस तरह कि

-(void)click:(id)sender 
{ 
    int clickcelltag; 
    clickcelltag=sender.tag; 

    NSIndexPath *index =[NSIndexPath indexPathForRow:clickcelltag inSection:0]; 

    [userreviewtblview scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];//userreviewtblview is a UITableView name 
} 

आशा इस तुम्हारी मदद करेगा संभव है :-)

संबंधित मुद्दे