باستخدام UISCREEN لقيادة شاشة VGA - لا يبدو أنه يعرض UIWINDOW؟

StackOverflow https://stackoverflow.com/questions/2660473

سؤال

أهلاً،

أحاول استخدام Uiscreen لقيادة شاشة منفصلة مع VGA Dongle على جهاز iPad الخاص بي.

إليك ما حصلت عليه في جهاز ViewDiddid -load الخاص بوحدة التحكم في عرض الجذر:

//Code to detect if an external display is connected to the iPad.
 NSLog(@"Number of screens: %d", [[UIScreen screens]count]);

 //Now, if there's an external screen, we need to find its modes, itereate through them and find the highest one. Once we have that mode, break out, and set the UIWindow.

 if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected to the device
 {
  CGSize max;
  UIScreenMode *maxScreenMode;
  for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
  {
   UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
   if(current.size.width > max.width);
   {
    max = current.size;
    maxScreenMode = current;
   }
  }
  //Now we have the highest mode. Turn the external display to use that mode.
  UIScreen *external = [[UIScreen screens] objectAtIndex:1];
  external.currentMode = maxScreenMode;
  //Boom! Now the external display is set to the proper mode. We need to now set the screen of a new UIWindow to the external screen
  external_disp = [externalDisplay alloc];
  external_disp.drawImage = drawViewController.drawImage;
  UIWindow *newwindow = [UIWindow alloc];
  [newwindow addSubview:external_disp.view];
  newwindow.screen = external;
 }
هل كانت مفيدة؟

المحلول

تحتاج إلى بدء نافذتك ...

 UIWindow *newwindow = [[UIWindow alloc] init];

نصائح أخرى

[newwindow makeKeyAndVisible];?

أعتقد أن مشكلتك هي externaldisplay. قم بإنشاء ViewController خارج الكود الخاص بك (ربما قم ببساطة بإضافة ملف ViewController جديد ووضع الأشياء في .xib) وجربه للتأكد من أن ViewController يعمل قبل الاتصال به في الشاشة الخارجية. إليك الكود الخاص بك مع التغييرات المقترحة الخاصة بي - [MainViewController View] هو ViewController الذي أنشأته في الخارج.

//Code to detect if an external display is connected to the iPad.
NSLog(@"Number of screens: %d", [[UIScreen screens]count]);

//Now, if there's an external screen, we need to find its modes, iterate
//through them and find the highest one. Once we have that mode, break out,
//and set the UIWindow.

if([[UIScreen screens]count] > 1) //if there are more than 1 screens connected
                                  //to the device
{
 CGSize max;
 UIScreenMode *maxScreenMode;
 for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
 {
  UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
  if(current.size.width > max.width);
  {
   max = current.size;
   maxScreenMode = current;
  }
 }
 //Now we have the highest mode. Turn the external display to use that mode.
 UIScreen *external = [[UIScreen screens] objectAtIndex:1];
 external.currentMode = maxScreenMode;
 //Boom! Now the external display is set to the proper mode. We need to now
 //set the screen of a new UIWindow to the external screen

 UIWindow *newwindow = [UIWindow alloc];

 [newwindow addSubview:[mainViewController view]];
 newwindow.screen = external;

 [newwindow makeKeyAndVisible];
 [newwindow setHidden:NO];
}

مجرد تسجيل هذا هنا في حالة تعثر أي شخص في هذا السؤال. لم أتمكن من الحصول على أي شيء لأظهر على الشاشة الثانية حتى أدركت أن مندوب التطبيق الخاص بي كان عليه أن يحتفظ بـ Uiwindow. لا يوجد لديه مالك طبيعي ، لذلك إذا قمت فقط بتعيين تلقائي منتظم ، فسيتم إصدار النافذة قبل عرضها على الإطلاق.

امل ان يساعد.

لقد قمت بتحميل عينة .xcodeproj في github.

أشرت إلى هذه الصفحة بشكل رئيسي.

شكرًا جزيلاً. قون

http://github.com/igaiga/ipaddisplayoutsample

يجب الإشارة إلى أن الكود المقدم في هذه الصفحة وعلى رابط Github بواسطة Igaiga هو مجرد "تحريك" (وليس استنساخ) العرض الذي عادة ما يكون على جهاز iPad (أو أي جهاز آخر).

إذا كنت بحاجة إلى استنساخ (AKA Mirror) طريقة العرض وتحديث محتوياته ، يكون هذا الرابط أكثر ملاءمة: http://www.touchcentric.com/blog/archives/123

آمل أن يساعد هذا في توضيح حالات الاستخدام لكلا مجموعتين من التعليمات البرمجية للمستخدمين الذين بدأوا للتو في دمج إمكانيات الفيديو في التطبيقات الموجودة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top