2012-10-25 4 views
8

में पेज कंट्रोल के साथ छवियों को स्वाइप करना मैं अभ्यास ऐप बनाने की कोशिश कर रहा हूं जहां मैं पेज नियंत्रण के साथ छवियों को स्क्रॉल कर सकता हूं। मैं छवियों को स्क्रॉल करने और पेज नियंत्रण को शामिल करने में सक्षम हूं। लेकिन मुझे जिस समस्या का सामना करना पड़ रहा है वह है कि मैं दोनों को अंतःस्थापित करने में सक्षम नहीं हूं। जब मैं छवियों को स्क्रॉल करता हूं तो कहने का मतलब है कि पृष्ठ नियंत्रण प्रभावित नहीं होता है और जब मैं पृष्ठ नियंत्रण बदलता हूं, तो छवियों की स्क्रॉलिंग अप्रभावित होती है।आईफोन

मैंने पृष्ठ नियंत्रण के साथ स्क्रॉलिंग के लिए यह http://www.iosdevnotes.com/2011/03/uiscrollview-paging/ संदर्भित किया है।

Viewcontroller.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UIScrollViewDelegate>{ 
    UIScrollView *scrollView; 
    UIPageControl *pageControl; 

    BOOL pageControlBeingUsed; 
} 

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView; 
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl; 

- (IBAction)changePage; 

@end 

Viewcontroller.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize scrollView,pageControl; 

- (void)scrollViewDidScroll:(UIScrollView *)sender { 
    if (!pageControlBeingUsed) { 
     // Switch the indicator when more than 50% of the previous/next page is visible 
     CGFloat pageWidth = self.scrollView.frame.size.width; 
     int page = floor((self.scrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1; 
     self.pageControl.currentPage = page; 
    } 
} 
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
    pageControlBeingUsed = NO; 
} 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 
    pageControlBeingUsed = NO; 
} 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSArray *images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"1.jpeg"],[UIImage imageNamed:@"2.jpeg"],[UIImage imageNamed:@"3.jpeg" ], nil]; 

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height); 

    for (int i = 0; i < images.count; i++) { 
     CGRect frame; 
     frame.origin.x = self.scrollView.frame.size.width * i; 
     frame.origin.y = 0; 
     frame.size = self.scrollView.frame.size; 
     UIImageView* imgView = [[UIImageView alloc] init]; 
     imgView.image = [images objectAtIndex:i]; 
     imgView.frame = frame; 
     [scrollView addSubview:imgView]; 
    } 

    self.pageControl.currentPage = 0; 
    self.pageControl.numberOfPages = images.count; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    self.scrollView = nil; 
    self.pageControl = nil; 
} 

- (IBAction)changePage{ 
     // update the scroll view to the appropriate page 
     CGRect frame; 
     frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage; 
     frame.origin.y = 0; 
     frame.size = self.scrollView.frame.size; 
     [self.scrollView scrollRectToVisible:frame animated:YES]; 
     pageControlBeingUsed = YES; 
} 

@end 

इस पर कुछ मार्गदर्शन चाहते हैं ... धन्यवाद ..

उत्तर

3

चेक आप पुस्तक को देखने के प्रतिनिधि निर्धारित किया है कि क्या ViewController

पर और आपने अभी पेज को नियंत्रित किया है कंट्रोलबिंग YES को या कोई और आप इसे ViewController

+0

यह जहां उपयोग करने के लिए? मुझे इसका उपयोग करने का विचार दे सकता है? – lakesh

+0

ने कोड को अभी बदल दिया है ... पृष्ठ शामिल है स्क्रॉलव्यूस्ड स्क्रॉल में नियंत्रण नियंत्रण .. अभी भी कोई अंतर नहीं है ... – lakesh

+0

क्षमा करें ... मेरे प्रतिनिधि को गलत तरीके से सेट करें .. मदद के लिए धन्यवाद ... – lakesh

4

में कहीं भी इस्तेमाल नहीं किया है मैं इस ट्यूटोरियल से पेज नियंत्रण और scrollview सीखा है, इसकी बहुत स्पष्ट रूप से लिखा है, यह आप में मदद करता है उम्मीद http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content

+1

को प्राप्त करने के लिए एक गोलाकार पथ के बाद अपनी अंगुली को ले जाना मतलब है मैंने ट्यूटोरियल के बाद नया अभ्यास ऐप बनाया है और यह अभी भी काम नहीं करता है ... – lakesh

+0

नए कोड के साथ भी यही समस्या है? –

+0

या ... यदि आवश्यक है, तो मैं इसके लिए एक नया प्रश्न शुरू कर सकता हूं ... – lakesh