2009-06-16 17 views
43

मैं कैमरा पूर्वावलोकन में ओवरले (UIImageView) कैसे जोड़ूं और इस पर स्पर्श संभाल कैसे करूं?आईफोन: कैमरा पूर्वावलोकन ओवरले

ऐसा करने के मेरे पिछले प्रयास (उदा। UIImagePickerController का उपयोग करें और छवि को सबव्यूव के रूप में जोड़ें) विफल हो गए हैं।

+85

बहुत बढ़िया जोड़ने चि त्र का री! – rpetrich

+2

क्या आपने इसे हल करने का अंत किया? – CodeAndCats

+3

एक तस्वीर एक हजार शब्द बोलती है – Unheilig

उत्तर

37

इस ट्यूटोरियल यह बताते हैं: http://www.musicalgeometry.com/?p=821

बस ओवरले दृश्य के बजाय लाल क्षेत्र ट्यूटोरियल में दिखाया गया है में एक UIImage जोड़ें।

+2

+1, अब यह स्पष्ट रूप से बेहतर उत्तर है। अगर मुझे गलत नहीं लगता है, तो कैमरा ओवरव्यू व्यू 3.1 एसडीके में जोड़ा गया था। – Henning

+0

हैलो मुझे भी जानकारी की आवश्यकता होगी लेकिन लिंक काम नहीं कर रहा है। क्या अन्य ट्यूटोरियल हैं? धन्यवाद –

+0

@ dtt101: आपका लिंक अब और मौजूद नहीं है! : नहीं मिला – Momi

3

आपके बजाय सीधे मुख्य विंडो के सबव्यूव के रूप में UIImageView जोड़ने में सक्षम हो सकते हैं, यह बेहतर काम कर सकता है। बस उन्हें सही क्रम में जोड़ने के लिए सुनिश्चित करें, या कैमरे के बाद

[window bringSubviewToFront:imageView]; 

पर कॉल करें।

आप UIImageView पर छूता है संभाल करने के लिए आप सिर्फ एक सामान्य फुलस्क्रीन View एक पारदर्शी पृष्ठभूमि के साथ की एक subview के रूप UIImageView जोड़ सकते हैं, और जोड़ने चाहते हैं कि खिड़की के बजाय, एक सामान्य UIViewController उपवर्ग के साथ कि आप कर सकते हैं स्पर्श घटनाओं को संभालने के लिए उपयोग करें।

2

अपने कार्यान्वयन फ़ाइल के लिए कैमरा ओवरले दृश्य (3.1 में उपलब्ध है और बाद में)

@property(nonatomic, retain) UIView *cameraOverlayView 
10

देखें:

- (IBAction)TakePicture:(id)sender { 

    // Create image picker controller 
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 

    // Set source to the camera 
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 

     // Delegate is self 
     imagePicker.delegate = self; 

     OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];  

     // Insert the overlay: 
     imagePicker.cameraOverlayView = overlay; 

     // Allow editing of image ? 
     imagePicker.allowsImageEditing = YES; 
     [imagePicker setCameraDevice: 
     UIImagePickerControllerCameraDeviceFront]; 
     [imagePicker setAllowsEditing:YES]; 
     imagePicker.showsCameraControls=YES; 
     imagePicker.navigationBarHidden=YES; 
     imagePicker.toolbarHidden=YES; 
     imagePicker.wantsFullScreenLayout=YES; 

     self.library = [[ALAssetsLibrary alloc] init]; 

     // Show image picker 
     [self presentModalViewController:imagePicker animated:YES]; 
    } 

एक UIView वर्ग बनाने और इस कोड

- (id)initWithFrame:(CGRect)frame 
    { 
     self = [super initWithFrame:frame]; 
     if (self) { 
      // Initialization code 


      // Clear the background of the overlay: 
      self.opaque = NO; 
      self.backgroundColor = [UIColor clearColor]; 

      // Load the image to show in the overlay: 
      UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"]; 
      UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic]; 
      overlayGraphicView.frame = CGRectMake(30, 100, 260, 200); 
      [self addSubview:overlayGraphicView]; 

     } 
     return self; 
    } 
संबंधित मुद्दे