2013-02-21 79 views
1

下面是我的代碼...我有是當拍攝照片時,由來自iphone裝置的相機,其可以LABELVIEW的imageview的後面獸皮的問題...視圖隱藏的ImageView後面

var win = Titanium.UI.createWindow({ 
     title : 'Photoshare', 
     fullscreen : false, 
     barColor : '#000000', 
     backgroundColor : '#fff' 
    }); 
    // creating scroll view 
    var scrollView = Titanium.UI.createScrollView({ 
     contentWidth : 'auto', 
     contentHeight : 'auto', 
     width : Titanium.Platform.displayCaps.platformWidth, 
     height : Titanium.Platform.displayCaps.platformHeight, 
     top : 0, 
     showVerticalScrollIndicator : false, 
     showHorizontalScrollIndicator : false, 
     minZoomScale : 0.1, 
     maxZoomScale : 100 
    }); 
    // creating parent view to contain imageview 
    var parentView = Titanium.UI.createView({ 
     width : Titanium.Platform.displayCaps.platformWidth, 
     height : Titanium.Platform.displayCaps.platformHeight, 
     top : 0 
    }); 
    scrollView.add(parentView); 
    // adding parent view to window 
    // win.add(parentView); 

    // creating image view 
    var imgView = Titanium.UI.createImageView({ 
     width : Titanium.Platform.displayCaps.platformWidth, 
     height : Titanium.Platform.displayCaps.platformHeight, 
     top : 0 
    }); 
    // adding imageview to parent view 
    parentView.add(imgView); 
    var labelView = Titanium.UI.createView({ 
     top : 280, 
     right : 0, 
     width : 200, 
     height : 100, 
     backgroundColor : '#000', 
     opacity : 0.5 
    }); 
    imgView.add(labelView); 
    // opening the camera at the start of the app 
    Titanium.Media.showCamera({ 
     saveToPhotoGallery : false, 
     allowEditing : false, 
     mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO], 
     success : function(event) { 
      var capturedImage = event.media; 
      imgView.image = capturedImage; 
     }, 
     cancel : function() { 
      scrollView.hide(); 
     }, 
     error : function(error) { 
      if (error.code == Titanium.Media.NO_CAMERA) { 
       alert('Please Run it on device'); 
      } 

     }, 
    }); 
    var currentLocationLabel = Titanium.UI.createLabel({ 
     left : 5, 
     // top : 2, 
     width : 'auto', 
     height : 15, 
     color : '#fff', 
     font : { 
      fontSize : 12 
     }, 
    }); 
    // labelView.add(currentLocationLabel); 
    var previousLocationLabel = Titanium.UI.createLabel({ 
     left : 5, 
     // top : 66, 
     width : 'auto', 
     height : 15, 
     color : '#fff', 
     font : { 
      fontSize : 12 
     }, 
    }); 

    var distanceLabel = Titanium.UI.createLabel({ 
     left : 5, 
     // top : 50, 
     width : 'auto', 
     height : 15, 
     color : '#fff', 
     font : { 
      fontSize : 12 
     }, 
    }); 
    var timeLabel = Titanium.UI.createLabel({ 
     left : 5, 
     // top : 18, 
     width : 'auto', 
     height : 15, 
     color : '#fff', 
     font : { 
      fontSize : 12 
     }, 
    }); 
    var weatherLabel = Titanium.UI.createLabel({ 
     left : 5, 
     // top : 34, 
     width : 'auto', 
     height : 15, 
     color : '#fff', 
     font : { 
      fontSize : 12 
     }, 
    }); 
    win.addEventListener('focus', function(e) { 
     var setTop = 2; 
    /* if (Ti.App.DataStorage.GetPreviousLocationVisibility() == 0) { 
      labelView.remove(previousLocationLabel); 
     } else { 
      labelView.add(previousLocationLabel); 
     }*/ 
     if (Ti.App.DataStorage.GetCurrentLocationVisibility() == 0) { 
      labelView.remove(currentLocationLabel); 
     } else { 
      currentLocationLabel.setTop(setTop); 
      labelView.add(currentLocationLabel); 
      setTop = setTop + 15; 
     } 

     if (Ti.App.DataStorage.GetTimeVisibility() == 0) { 
      labelView.remove(timeLabel); 
     } else { 
      timeLabel.setTop(setTop); 
      labelView.add(timeLabel); 
      setTop = setTop + 15; 
     } 
     if (Ti.App.DataStorage.GetWeatherVisibility() == 0) { 
      labelView.remove(weatherLabel); 
     } else { 
      weatherLabel.setTop(setTop); 
      labelView.add(weatherLabel); 
      setTop = setTop + 15; 
     } 
     if (Ti.App.DataStorage.GetDistanceVisibility() == 0) { 
      labelView.remove(distanceLabel); 
     } else { 
      distanceLabel.setTop(setTop); 
      labelView.add(distanceLabel); 
      setTop = setTop + 15; 
     } 
    }); 

任何人都可以告訴我,我做錯了什麼...需要幫助

回答

2

一個潛在的問題可能是這樣的:

imgView.add(labelView); 

添加視圖到ImageView的是未定義行爲,這是考慮編輯非容器視圖。對我而言,這導致我的觀點隨機不顯示,或置於一個奇怪的位置。解決方案是創建一個容器視圖,將imgView放在該視圖中,然後將labelView放在它的頂部。

The docs make an obscure mention of this,但它逃過了我很長一段時間,造成了許多麻煩,指的ImageViews和其他非容器的觀點:

Adding children to the these views may be supported on some platforms, 
but is not guaranteed to work across platforms. Where it is supported, 
it may not work as expected. 

一般規律是要經常檢查並確保您的通話add組件在支持它。