2012-11-28 15 views
6

मैं एक आईफोन ऐप बना रहा हूं जिसमें मुझे UIScrollView के अंदर कुछ छवियां दिखाने की ज़रूरत है, बाएं और दाएं उपयोगकर्ता दो बटन होंगे जो उपयोगकर्ता बटन पर क्लिक कर सकते हैं और यह अगला या पिछली छवि इसके अलावा नीचे एक बटन भी है, जब उपयोगकर्ता उस बटन पर क्लिक करेगा, यह उस छवि को दिखाएगा जिसे हमने स्क्रॉलव्यू में चुना है। मैं जानना चाहता हूं कि हम उस स्क्रॉलव्यू के अंदर कई छवियां कैसे दिखाते हैं और नीचे बटन का चयन करते समय, कैसे करें स्क्रॉलव्यू के अंदर कौन सी छवि थी।आईओएस में UIScrollView के अंदर एकाधिक छवियों को कैसे दिखाएं

+0

आप क्या किया है अब तक –

+0

सीधा कोड प्राप्त करने के लिए लगता है? क्या किया है और इस पर काम किया है? –

उत्तर

5

danielbeard.wordpress से एक उदाहरण .com

मामले में अपनी छवि के नाम सिर्फ संख्या नहीं हैं:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 

    [scrollView setPagingEnabled:YES]; 
    [scrollView setAlwaysBounceVertical:NO]; 

    NSArray *imagesArray = [NSArray arrayWithObjects:@"img1.png", @"img2.png", @"img3.png", nil]; 

    for (int i = 0; i < [imagesArray count]; i++) 
    { 
     CGFloat xOrigin = i * scrollView.frame.size.width; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; 
     [imageView setImage:[UIImage imageNamed:[imagesArray objectAtIndex:i]]]; 
     [imageView setContentMode:UIViewContentModeScaleAspectFit]; 

     [scrollView addSubview:imageView]; 
    } 

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [imagesArray count], scrollView.frame.size.height)]; 
+0

मैंने यह किया और पोर्ट्रेट मोड के लिए ठीक काम करता है। लेकिन अगर मैं अलग छवि सरणी है तो मैं लैंडस्केप मोड के लिए इसे कैसे कर सकता हूं? कृपया इस पर कुछ सुझाव दें। – Mak13

+0

आपको पता होना चाहिए कि स्क्रीन लैंडस्केप मोड में घुमाए जाने पर। एक बार पता चला कि छवियों के सरणी में छवि नाम बदलते हैं तो पुराने स्क्रॉलव्यू को हटा दें और नई छवि सरणी के साथ एक नया ड्रा करें। – tnylee

+0

मैंने केवल उसी दिन ही किया था। वैसे भी उत्तर के लिए धन्यवाद। – Mak13

2

Apple.developerPhotoScroller एम्बेडेड UIScrollViews और CATiledLayer के उपयोग को प्रदर्शित करने और तस्वीरें कि व्यक्तिगत रूप से आलोचना की जा सकती है और जूम paginating के लिए एक अमीर उपयोगकर्ता अनुभव बनाने के लिए यह दर्शाता है।

कैटिल्डलेयर का उपयोग उच्च-रिज़ॉल्यूशन छवियों या फ़ोटो के बड़े सेट के साथ पेजिंग, पैनिंग और ज़ूमिंग के प्रदर्शन को बढ़ाने के लिए किया जाता है।

0

आप बस पहले क्रम और छवि पर कोई नया दृश्य बना सकते हैं और टैग मान पर टैग 1000 या 100 और वेतन वृद्धि की तरह सभी दृश्यों आवंटित और फिर करने के लिए इस दृश्य जोड़ने scrollview और छोड़ दिया और सही चलती के लिए दो बटन और उनके आउटलेट कार्यों बनाने के लिए और इस

 indexStart=100; 
UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)]; 

       AddView.tag=indexStart; 
       btnTap.tag=indexStart; 

       UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; 



       [AddView addSubview:imgview]; 

       imgview.image=image; 
       imgview.tag=1000; 
       [ScrollView addSubview:AddView]; 
       [imgArray addObject:AddView]; 

आप और छोड़ दिया और सही बटन आप इसका उपयोग पर यह करने के लिए लूप का उपयोग तरह एक परिवर्तनशील सरणी में सभी scrollview उप दृश्य जोड़ कोड और इस कोड में संपादित करें ImgeView छवि दृश्य i है I Nbetween छोड़ दिया और सही बटन जहाँ आप छवि तुम सिर्फ सरल indexstart ++ या दिखाने - यदि उपयोगकर्ता दाएं या बाएं बटन का चयन

for (int index = 0; index < [imgAddArrayAfter count]; index ++) { 
     NSLog(@"index %d",index); 
     UIView *vc=[imgArray objectAtIndex:index]; 
     NSLog(@"view tag %d",vc.tag); 
     if(vc.tag == indexStart) 
     { 

      UIImageView *modalView=(UIImageView *) [vc viewWithTag:1000]; 
      editImgeView.image=modalView.image; 
     } 
    } 

मैं आशा है कि आप समझते हैं ;-)

0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    scrollView.contentSize = CGSizeMake(320, 465); 

    [scrollView setScrollEnabled:YES]; 
    [scrollView setPagingEnabled:YES]; 
    [scrollView setAlwaysBounceVertical:NO]; 
    [self.view addSubview:scrollView]; 

    NSMutableArray *arrImage = [NSMutableArray arrayWithObjects:@"food1.jpeg", @"food2.jpeg", @"food3.jpeg",@"food4.jpeg", @"food5.jpeg", @"food6.jpeg",@"food7.jpeg", @"food8.jpeg", @"foo9.jpeg",@"food10.jpeg", @"food11.jpeg", @"food12.jpeg",@"food13.jpeg", @"food14.jpeg", @"food15.jpeg", @"food16.jpeg", nil]; 

    for (int i = 0; i < [arrImage count]; i++) 
    { 
     CGFloat xOrigin = i * scrollView.frame.size.width; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; 
     [imageView setImage:[UIImage imageNamed:[arrImage objectAtIndex:i]]]; 
     [imageView setContentMode:UIViewContentModeScaleAspectFit]; 

     [scrollView addSubview:imageView]; 
    } 

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [arrImage count], scrollView.frame.size.height)]; 
} 
संबंधित मुद्दे