2013-07-19 3 views
8

मैं एक फेसबुक जैसी आईओएस ऐप बनाना चाहता हूं, जो उपयोगकर्ता उस समय टैप करते समय टाइमलाइन पूर्ण स्क्रीन से एक तस्वीर बनाता है।स्पर्श किए जाने पर मैं छवि को पूर्ण स्क्रीन पर कैसे विस्तारित करूं?

अद्यतन:

मैं सेल में छवि प्रदर्शित करने UICollectionView उपयोग कर रहा हूँ, इसलिए मैं collectionView:didSelectItemAtIndexPath: विधि का उपयोग करना चाहिए लगता है? और imageView सेल में है, तो क्या मैं अभी भी पूर्ण स्क्रीन पर सीधे विस्तार कर सकता हूं?

नीचे एक जोड़ी छवियों संलग्न:

enter image description here

enter image description here

उत्तर

5

उपयोग UITapGestureRecognizer, और मत भूलना, क्योंकि डिफ़ॉल्ट छवि से UserInteraction नहीं होने imageView.userInteractionEnabled = YES; स्थापित करने के लिए।

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; 
[singleTap setNumberOfTapsRequired:1]; 

[imageView addGestureRecognizer:singleTap]; 


-(void)handleSingleTap:(id)sender { 
// push you view here 
//code for full screen image 
} 
+0

माफी। मैं सेल में छवि प्रदर्शित करने के लिए UICollectionView का उपयोग कर रहा हूं, ऐसा लगता है कि मुझे संग्रह दृश्य का उपयोग करना चाहिए: didSelectItemAtIndexPath: विधि? और imageView सेल में है, तो क्या मैं अभी भी पूर्ण स्क्रीन पर सीधे विस्तार कर सकता हूं? –

+0

@ सेराफ जे लिन: हाँ एक बार टॉमस्विफ्ट के जवाब की जांच करें। धुंधला विवरण के लिए – Balu

0

मैं क्या समझ में आ आप UIWebView में अपनी छवि है कि यह वही है मैं इस समय है है, स्वयं को UIWebViews प्रतिनिधि सेट तो इस जोड़ें:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { 
    if (navigationType == UIWebViewNavigationTypeLinkClicked) { 
     NSURL *URL = [request URL];   
     ImageViewer *imageView = [[[ImageViewer alloc] initWithNibName:@"ImageViewer" bundle:nil] autorelease]; 
     imageView.imageURL = URL; 
     [self presentModalViewController:imageView animated:YES]; 
     return NO; 
    } else { 
     return YES; 
    } 
} 

बस छवि एक बनाने के एचटीएमएल में लिंक जैसे आप सामान्य रूप से करेंगे। यदि आपके पास अन्य लिंक हैं जो आप किसी मॉडल में लोड नहीं करना चाहते हैं तो आप यह पता लगाने के लिए कोड को संशोधित कर सकते हैं कि क्या दबाया जा रहा लिंक किसी छवि पर जा रहा है अन्यथा बस हाँ वापस करें;

मैं जो मैं यहाँ पोस्ट किया है मेरी वेबव्यू साथ एक छोटी सी समस्या आ रही है (बस बैठाना आप कुछ समस्या मिल !!) Code.

आशा इस मदद करता है!

+0

माफी। मैं सेल में छवि प्रदर्शित करने के लिए UICollectionView का उपयोग कर रहा हूं, और imageView सेल में है, तो क्या मैं अभी भी पूर्ण स्क्रीन पर सीधे विस्तार कर सकता हूं? –

+0

ठीक नहीं Probs .. एक और जवाब जोड़ना :) –

13

यहां एक काफी बुनियादी समाधान है। यह मानता है कि आपके संग्रह कक्ष में UIImageView UICollectionViewCell सामग्री दृश्य का एकमात्र सबव्यूव्यू है।

#import <objc/runtime.h> // for objc_setAssociatedObject/objc_getAssociatedObject 

...

- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath]; 

    UIImageView* iv = cell.contentView.subviews.lastObject; 

    UIImageView* ivExpand = [[UIImageView alloc] initWithImage: iv.image]; 
    ivExpand.contentMode = iv.contentMode; 
    ivExpand.frame = [self.view convertRect: iv.frame fromView: iv.superview]; 
    ivExpand.userInteractionEnabled = YES; 
    ivExpand.clipsToBounds = YES; 

    objc_setAssociatedObject(ivExpand, 
           "original_frame", 
           [NSValue valueWithCGRect: ivExpand.frame], 
           OBJC_ASSOCIATION_RETAIN); 

    [UIView transitionWithView: self.view 
         duration: 1.0 
         options: UIViewAnimationOptionAllowAnimatedContent 
        animations:^{ 

         [self.view addSubview: ivExpand]; 
         ivExpand.frame = self.view.bounds; 

        } completion:^(BOOL finished) { 

         UITapGestureRecognizer* tgr = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(onTap:)]; 
         [ivExpand addGestureRecognizer: tgr]; 
        }]; 
} 

- (void) onTap: (UITapGestureRecognizer*) tgr 
{ 
    [UIView animateWithDuration: 1.0 
        animations:^{ 

         tgr.view.frame = [objc_getAssociatedObject(tgr.view, 
                    "original_frame") CGRectValue]; 
        } completion:^(BOOL finished) { 

         [tgr.view removeFromSuperview]; 
        }]; 
} 
+0

आपकी टिप्पणी के लिए धन्यवाद, मैं कल इस कोड को आजमाउंगा। लेकिन यह मेरी उम्मीद से थोड़ा सा लगता है ... ऊपर दिए गए कोड को पॉप्युलेट करने के बाद, जब मैं फोटो को स्पर्श करता हूं, तो यह पूर्ण स्क्रीन तक फैलता है, लेकिन मेरी टैब बार और नेवी बार दोनों अभी भी वहां हैं, और जब मैं विंडो को ऊपर या नीचे स्क्रॉल करता हूं , तस्वीर बस वहां रहती है। मुझे आशा है कि उपयोगकर्ता पूर्ण स्क्रीन मोड में आने के बाद भी उपयोगकर्ता अन्य फ़ोटो ब्राउज़ करने के लिए स्वाइप कर सकता है। मैंने अन्य प्रश्नों को ब्राउज़ किया है, शायद मुझे जो चाहिए वह एक और दृश्य नियंत्रक को धक्का दे रहा है? इस बीच, मुझे आशा है कि उपयोगकर्ता एक बार एक तस्वीर को स्वाइप कर सकता है, थोड़ा बाउंस, जैसे आईओएस फोटो कैमरा रोल पूर्ण स्क्रीन गैलरी। –

+0

यदि आप इसे अपने टैब और एनएवी नियंत्रकों को ओवरले करना चाहते हैं तो [self.view addSubview: ivExpand] बदलें; [self.view.window addSubview]; आपको convertRect: कॉल को अपडेट करने की भी आवश्यकता होगी। एक पूर्ण पूर्ण स्क्रीन गैलरी व्यूअर जोड़ना थोड़ा और काम है, हां। – TomSwift

0

आप ठीक कह रहे हैं, का प्रयोग करें UICollectionView के प्रतिनिधि विधि: धुंधला विवरण के लिए

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //get UIImage from source 
    //show (add subView) UIImageView with full screen frame 
    //add gesture for double tap on which remove UIImageView 
} 
संबंधित मुद्दे