6

Hızlı bir sorum var, cevap vermeme yardımcı olabileceğinizi umuyordum. Şu anda, üzerinde hangi noktaya bağlı olarak bir görüntüyü değiştiren bir storyboard içinde bir UIPageControl var, ancak, artık nokta/görüntülerde değişiklik yapmak için noktaya basmanız gerekiyor, resimlerle/noktalarla nasıl değişebilirim? swiping tarafından?Xcode: Kaydırma hareketiyle UIPageControl değerini nasıl değiştirebilirim?

İşte burada Herhangi bir yardım büyük takdir

#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 

benim .m benim kodudur benim .h

#import <UIKit/UIKit.h> 

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

@end 

benim kodudur. Teşekkürler

cevap

15

UISwipeGestureRecognizer'ı görünümünüze ve UIDageControl nesnesinin yönlendirme yöntemine göre UISwipeGestureRecognizer'ın selektör yöntemine ekleyerek geçerli sayfayı veya azaltmayı artırabilirsiniz.

Aşağıdaki kodu kullanabilirsiniz.

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]; 

kaydırın jest seçici

- (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]]; 
} 

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

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

@end 
+0

Müthiş .h dosyasında UIPageControl için bir çıkış ekleme, diyor görünüm kontrolöre hızlıca kaydırma hareketini ekleme bu "sayfa" bildirilmemiş bir tanımlayıcıdır. Ve bunu eklemek nerede uygun? Herhangi bir yardım? –

+0

Ah üzgünüm! bahsetmeyi unuttuğunuz sayfa UIPageControl nesnenizdir. –

+0

Cevabımı düzenledim, lütfen kontrol edin –

İlgili konular