2012-09-21 16 views
13

क्या आईओएस में टैब स्विच करने के लिए स्क्रीन पर कहीं भी बाएं या दाएं स्वाइप करना संभव है? धन्यवादआईओएस: टैब के बीच बाएं/दाएं स्वाइप करें?

उदाहरण 1: बस स्वाइप करके कैलेंडर पर महीने के बीच स्विचिंग बायीं/दायीं उदाहरण 2: शुरू 0:12 http://www.youtube.com/watch?v=5iX4vcsSst8

उत्तर

1

ज़रूर पर, यह संभव है।

प्रत्येक स्क्रीन को स्वाइप के लिए UISwipeGestureRecognizer होने की आवश्यकता होगी, फिर टैब बार को वांछित कार्रवाई करने के लिए कॉल करें। जो कुछ भी आप चाहते हैं उस सक्रिय टैब को बढ़ाने या घटाने से कुछ भी हो सकता है।

कोड दोहराव रोकथाम के लिए, आप एक कस्टम UIViewController बना सकते हैं और अपने सभी दृश्य नियंत्रकों वहाँ से विरासत (या कुछ अन्य तरीकों से) हो सकता था।

20

यदि आप एक टैब बार नियंत्रक का उपयोग कर रहे हैं, तो आप प्रत्येक टैब के दृश्य पर एक स्वाइप इशारा पहचानकर्ता स्थापित कर सकते हैं। जब इशारा पहचानकर्ता ट्रिगर होता है, तो यह टैबबारकंट्रोलर बदल सकता है। चयन किए गए TabIndex

यह प्रभाव एनिमेटेड नहीं होगा, लेकिन यह टैब को एक स्वाइप इशारा के साथ स्विच करेगा। यह लगभग तब था जब मैंने यूआईटीएबीबार के साथ एक ऐप किया था जिसमें बाएं और दाएं तरफ बटन थे और सक्रिय टैब को बदलने के लिए इशारे को स्वाइप किया था।

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

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

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

- (IBAction)tappedRightButton:(id)sender 
{ 
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex]; 

    [rootVC.tabBarController setSelectedIndex:selectedIndex + 1]; 
} 

- (IBAction)tappedLeftButton:(id)sender 
{ 
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex]; 

    [rootVC.tabBarController setSelectedIndex:selectedIndex - 1]; 
} 
+0

तो मूल पोस्ट में एंड्रॉइड यूट्यूब उदाहरण में एनिमेट करना संभव नहीं होगा? – user1689272

+1

मैंने अतीत में अधिक तरल टैब नियंत्रण बनाए हैं और यह उपरोक्त टैब बार उदाहरण से कहीं अधिक कस्टम समाधान था। आखिरी बार मैंने ऐसा कुछ किया, मैंने वास्तव में एक लंबा दृश्य नियंत्रक बनाया जिसमें सभी अनुभाग दृश्य नियंत्रकों को एक तरफ रखा गया था (मेरे पास 5 अनुभाग थे, ताकि वीसी स्क्रीन चौड़ाई 5x थी)। नेविगेशन में कंटेनर वीसी को बाएं और दाएं स्लाइडिंग शामिल है। यह सबसे अच्छा तरीका नहीं है क्योंकि सभी वीसी हर समय स्मृति में रहते हैं, लेकिन यह सबसे अच्छा है जिसके लिए मुझे इसकी आवश्यकता होती है। मैं दुर्भाग्य से उस से कोई कोड स्निपेट नहीं दिखा सकता। – skladek

+3

आईओएस 7 के रूप में, इस प्रभाव को पूरा करने के लिए कस्टम व्यू कंट्रोलर संक्रमण के साथ 'UIPercentDrivenInteractiveTransition' का उपयोग करना संभव है। मूल रूप से आपके पास स्लाइडिंग करने के लिए एक कस्टम पुश/पॉप एनीमेशन के साथ एक नेविगेशन नियंत्रक होगा। UIPercentDrivenInteractiveTransition संक्रमण को स्वाइप के बजाए पैन के रूप में ट्रैक करने की अनुमति देगा। – skladek

6

इस प्रयास करें,

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

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

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

- (IBAction)tappedRightButton:(id)sender 
{ 
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex]; 

    [self.tabBarController setSelectedIndex:selectedIndex + 1]; 

    //To animate use this code 
    CATransition *anim= [CATransition animation]; 
    [anim setType:kCATransitionPush]; 
    [anim setSubtype:kCATransitionFromRight]; 
    [anim setDuration:1]; 
    [anim setTimingFunction:[CAMediaTimingFunction functionWithName: 
            kCAMediaTimingFunctionEaseIn]]; 
    [self.tabBarController.view.layer addAnimation:anim forKey:@"fadeTransition"]; 
} 

- (IBAction)tappedLeftButton:(id)sender 
{ 
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex]; 

    [self.tabBarController setSelectedIndex:selectedIndex - 1]; 

    CATransition *anim= [CATransition animation]; 
    [anim setType:kCATransitionPush]; 
    [anim setSubtype:kCATransitionFromRight]; 

    [anim setDuration:1]; 
    [anim setTimingFunction:[CAMediaTimingFunction functionWithName: 
           kCAMediaTimingFunctionEaseIn]]; 
    [self.tabBarController.view.layer addAnimation:anim forKey:@"fadeTransition"]; 
} 
+0

मुद्दों की जांच करना बहुत खुशी होगी, धन्यवाद, यह वास्तव में मदद करता है। –

2

कर सकते हैं UITabBarConroller

सभी अपने बच्चे ViewControllers प्रयोग कर रहे हैं मान लिया जाये एक वर्ग से विरासत जो आपके लिए भारी भारोत्तोलन करता है।

यह मैं इसे कैसे

class SwipableTabVC : UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let left = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft)) 
     left.direction = .left 
     self.view.addGestureRecognizer(left) 

     let right = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight)) 
     right.direction = .right 
     self.view.addGestureRecognizer(right) 
    } 

    func swipeLeft() { 
     let total = self.tabBarController!.viewControllers!.count - 1 
     tabBarController!.selectedIndex = min(total, tabBarController!.selectedIndex + 1) 

    } 

    func swipeRight() { 
     tabBarController!.selectedIndex = max(0, tabBarController!.selectedIndex - 1) 
    } 
} 

तो अपने सभी viewcontrollers कि UITabControllers का हिस्सा हैं SwipableTabVC UIViewController के बजाय से विरासत कर सकते हैं किया है।

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