2017-05-21 5 views
0

J'essaie d'avoir une vue déroulante qui occupe tout l'écran lorsque l'appareil est en mode paysage mais pas en mode portrait. C'est ma vue en mode portrait. Je souhaite que cela fonctionne de la même façon que l'application YouTube fonctionne avec la vidéo. Tout code exemple serait très utileswift défilement plein écran en mode paysage

enter image description here

Voilà comment je suis en train de mon rouleau Voir

DispatchQueue.main.async(execute: {() -> Void in 
      let imgURL = NSURL(string: self.property[i].image) 
      let data = NSData(contentsOf: (imgURL as URL?)!) 
      let imageView = UIImageView() 
      imageView.image = UIImage(data: data! as Data) 
      let xPosition = self.view.frame.width * CGFloat(i) 
      imageView.frame = CGRect(x: xPosition, y: 0, width: self.imageScrollView.frame.width, height: self.imageScrollView.frame.height) 

      self.imageScrollView.contentSize.width = self.imageScrollView.frame.width * CGFloat(i + 1) 
      self.imageScrollView.addSubview(imageView) 
     }) //End DispatchQueue 

Répondre

1

Utilisez-vous autolayout ce point de vue? le cas échéant, vous pouvez changer pour vos besoins de constarints du ScrollView lorsque l'orientation change (vous pouvez utiliser UIDeviceOrientationDidChangeNotification) ou si vous configurez simplement le cadre dans le code faire le réglage du cadre en conséquence

notification de registre dans votre viewWillAppear

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

et cette méthode sera appelé à l'orientation change

-

(void)orientationChanged:(NSNotification *)notification{ 

switch ([[UIApplication sharedApplication] statusBarOrientation]) 
    { 
     case UIInterfaceOrientationPortrait: 
     case UIInterfaceOrientationPortraitUpsideDown: 
     { 
     //set frame/ constarints for portrait  
     } 

      break; 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
     { 
     //set frame/ constarints for landscape 
     } 
      break; 
     case UIInterfaceOrientationUnknown:break; 
    } 

} 

Ne pas oublier d'enlever l'observateur

-(void)viewDidDisappear:(BOOL)animated{ 
    [super viewDidDisappear:animated]; 
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; 
}