6

मेरे पास एक त्वरित सवाल है कि मैं उम्मीद कर रहा था कि लोग मुझे जवाब देने में मदद कर सकते हैं। अभी मेरे पास एक स्टोरीबोर्ड में एक यूआईपीएज कंट्रोल है जो आप जिस बिंदु पर हैं, उसके आधार पर एक छवि को बदलता है, हालांकि, अब आपको डॉट्स/छवियों के माध्यम से बदलने के लिए डॉट पर प्रेस करना होगा, मैं छवियों/बिंदुओं के माध्यम से कैसे बदल सकता हूं स्वाइप करके?एक्सकोड: मैं स्वाइप इशारा के साथ UIPageControl मान कैसे बदलूं?

यहाँ मेरी ज

#import <UIKit/UIKit.h> 

@interface PageViewController : UIViewController 
@property (strong, nonatomic) IBOutlet UIImageView *dssview; 
- (IBAction)changephoto:(UIPageControl *)sender; 

@end 

के लिए मेरे कोड यहाँ मेरी मीटर के लिए मेरे कोड

#import "PageViewController.h" 

@interface PageViewController() 
@end 

@implementation PageViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
    // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)changephoto:(UIPageControl *)sender { 
    _dssview.image = [UIImage imageNamed: 
        [NSString stringWithFormat:@"%d.jpg",sender.currentPage+1]]; 
} 
@end 

किसी भी मदद की बहुत सराहना की जाएगी है। धन्यवाद

उत्तर

15

आप UISwipeGestureRecognizer को अपने दृश्य में और UISwipeGestureRecognizer के चयनकर्ता विधि में UIPageControl ऑब्जेक्ट को अद्यतन करने के दिशा में जोड़ सकते हैं, या तो वर्तमान पृष्ठ या कमी को बढ़ा सकते हैं।

आप नीचे दिए गए कोड का संदर्भ दे सकते हैं। दृश्य नियंत्रक

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; 
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; 
[self.view addGestureRecognizer:swipeLeft]; 

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; 
swipeRight.direction = UISwipeGestureRecognizerDirectionRight; 
[self.view addGestureRecognizer:swipeRight]; 

स्वाइप इशारा चयनकर्ता

- (void)swipe:(UISwipeGestureRecognizer *)swipeRecogniser 
{ 
    if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionLeft) 
    { 
     self.pageControl.currentPage -=1; 
    } 
    else if ([swipeRecogniser direction] == UISwipeGestureRecognizerDirectionRight) 
    { 
     self.pageControl.currentPage +=1; 
    } 
    _dssview.image = [UIImage imageNamed: 
       [NSString stringWithFormat:@"%d.jpg",self.pageControl.currentPage]]; 
} 

ज फ़ाइल में UIPageControl के एक आउटलेट जोड़े

@interface PageViewController : UIViewController 
@property (strong, nonatomic) IBOutlet UIImageView *dssview; 
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl; 

- (IBAction)changephoto:(UIPageControl *)sender; 

@end 
+0

बहुत बढ़िया है, यह कहना है करने के लिए कड़ी चोट इशारा जोड़ना कि "पृष्ठ" एक अविकसित पहचानकर्ता है। और यह जोड़ने के लिए उचित कहां है? कोई मदद? –

+0

ओह क्षमा करें! उल्लेख करना भूल गया, पृष्ठ आपकी यूआईपीएज नियंत्रण वस्तु है। –

+0

मैंने अपना जवाब संपादित कर लिया है, कृपया –

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