سؤال

لدي إعداد MpmoviePlayer لتشغيل فيلم مقدمة لتطبيقي. هذا رائع ، المشكلة الوحيدة هي أنها تستمر لمدة 14 ثانية ، وأريد أن أعطي المستخدمين فرصة لتخطي المقدمة بالضغط في أي مكان على الفيلم.

لقد أخفيت عناصر التحكم في الفيلم ، حيث أنها غير مطلوبة.

شفرة:

NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play]; 

شكرًا لك!

هل كانت مفيدة؟

المحلول

تحرير: لن يعمل الحل الأولي الخاص بي ، لأن الفيلم يتم عرضه في نافذة ثانية ، على أعلى النافذة الرئيسية للتطبيق (من النادر جدًا أن يكون لديك أكثر من نافذة في التسلسل الهرمي للعرض على iPhone). هذا الحل ، على أساس رمز عينة من ألعاب Apple من Apple, ، تعمل:

. . .
    // assuming you have prepared your movie player, as in the question
    [self.intro play];

    NSArray* windows = [[UIApplication sharedApplication] windows];
    // There should be more than one window, because the movie plays in its own window
    if ([windows count] > 1)
    {
        // The movie's window is the one that is active
        UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
        // Now we create an invisible control with the same size as the window
        UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];

        // We want to get notified whenever the overlay control is touched
        [overlay addTarget:self action:@selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];

        // Add the overlay to the window's subviews
        [moviePlayerWindow addSubview:overlay];
    }
. . .

// This is the method we registered to be called when the movie window is touched
-(void)movieWindowTouched:(UIControl*)sender
{
    [self.intro stop];
}

NB: يجب عليك حفظ الإشارة إلى مشغل الفيلم في متغير مثيل ، وهو الأكثر ملاءمة لإعلان خاصية يمكننا استخدامها للوصول إليها. لهذا السبب هو الاستخدام self.intro بدلا من مجرد intro في المثال. إذا كنت لا تعرف كيفية إعلان متغير مثيل وخاصية ، فهناك الكثير من المعلومات على هذا الموقع وأماكن أخرى.

**** الإجابة الأصلية أدناه

(لا يعمل في هذه الحالة ، ولكن في العديد من السيناريوهات المماثلة ، لذلك سأترك الأمر كمثال تحذير و/أو ملهم.)

. . . إذا لم يكن هناك شيء آخر ، فإنني أوصي بتصنيف UiWindow وتأكد من أن مندوب التطبيق الخاص بك يثبت أنه بدلاً من uiwindow العادية. يمكنك اعتراض اللمسات في تلك الفئة وإرسال إشعار أو إلغاء الفيلم مباشرة (إذا قمت بتخزين مؤشر إلى MpmoviePlayer في Ivar على الفئة الفرعية للنافذة).

@interface MyWindow : UIWindow {
}
@end

@implementation MyWindow
// All touch events get passed through this method
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
   // The screen has been touched, send a notification or stop the movie
   return [super hitTest:point withEvent:event];
}
@end
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top