ตรวจจับการหมุนในคลาสย่อย UIInputViewController ส่วนขยายแป้นพิมพ์

ฉันได้พัฒนาส่วนขยายแป้นพิมพ์แบบกำหนดเอง และฉันต้องอัปเดตข้อจำกัดบางประการโดยทางโปรแกรมหลังจากที่อุปกรณ์หมุน ฉันพยายามตรวจจับการหมุนส่วนต่อประสานผู้ใช้ในคลาสย่อย UIInputViewController ของฉัน แต่ไม่ประสบความสำเร็จ วิธีการเหล่านี้จะไม่ถูกเรียกเมื่ออุปกรณ์หมุน:

-(void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>) coordinator { NSLog(@"Orientation changed"); }

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { NSLog(@"Orientation changed"); }

ฉันได้ลองสังเกต UIDeviceOrientationDidChangeNotification แล้ว แต่ก็ไม่ได้ผลเช่นกัน

ไม่มีใครรู้วิธีตรวจจับการหมุนใน UIInputViewController หรือไม่


person Guferos    schedule 27.09.2014    source แหล่งที่มา
comment
ใน IOS10 viewWillTransitionToSize ถูกทริกเกอร์ใน UIInputViewController   -  person EckhardN    schedule 15.04.2018


คำตอบ (3)


คุณถูกต้อง - วิธีการเหล่านั้นไม่ได้ถูกเรียกในคลาสย่อย UIInputViewController สำหรับส่วนขยายแป้นพิมพ์ (ไม่แน่ใจเกี่ยวกับส่วนขยายประเภทอื่น)

คุณต้องแทนที่ viewDidLayoutSubviews

ตัวอย่างเช่น หากคุณต้องการอัปเดตเค้าโครงของมุมมองย่อย UICollectionView ของแป้นพิมพ์เมื่ออุปกรณ์หมุน คุณจะต้องดำเนินการดังนี้:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    [self.keyboard.collectionView performBatchUpdates:nil completion:nil];
}

ในกรณีของคุณ คุณสามารถตรวจสอบการวางแนวของอุปกรณ์ใน viewDidLayoutSubviews จากนั้นใช้/แก้ไขข้อจำกัดได้อย่างเหมาะสม

person siburb    schedule 03.10.2014

สวิฟท์ 4.2

  override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {        
       let screen = UIScreen.main.bounds
        if screen.width < screen.height {
            print("!!! portrait")
        } else {
            print("!!! landspace")
        }
     }
person Ahmadreza    schedule 03.12.2018

ดูเหมือนว่า Apple ไม่ได้จัดเตรียมวิธี API นี้ให้กับ UIInputViewController

คุณสามารถอนุมานการวางแนวอุปกรณ์ได้หากความกว้างของอุปกรณ์มากกว่าความสูงของอุปกรณ์ใน viewWillAppear

person nurnachman    schedule 03.10.2014