2010-04-22 14 views
23

की प्रस्तुति के समान पॉप एनीमेशन बनाना, मैं यूआईएलर्टव्यू - एक पॉप/वसंत के समान तरीके से एक दृश्य प्रस्तुत करना चाहता हूं। दुर्भाग्य से UIAlertView subclassing दृश्य के लिए एक विकल्प नहीं है जिसे मुझे पेश करने की आवश्यकता है। मैंने कुछ कोड लिखा है, लेकिन मुझे यह यथार्थवादी नहीं लगता है जितना मैं चाहूंगा। मैं अधिक यथार्थवाद या किसी लिंक के लिए किसी भी सुझाव की सराहना करता हूं यदि कुछ भी ऐसा ही किया गया है (मुझे Google पर कुछ भी नहीं मिला)। धन्यवाद।UIAlertView

- (id)initWithFrame:(CGRect)frame { 
    if ((self = [super initWithFrame:frame])) { 

     self.backgroundColor = [UIColor whiteColor]; 

     v = [[UIView alloc] initWithFrame:CGRectMake(140, 140, 60, 60)]; 
     v.backgroundColor = [UIColor blueColor]; 

     [self addSubview:v]; 
     [self animate]; 

    } 
    return self; 
} 

- (void)animate { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [UIView setAnimationDuration:0.2]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(popStep1Complete)]; 
    v.frame = CGRectMake(90, 90, 140, 140); 
    [UIView commitAnimations]; 
} 

- (void)popStep1Complete { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [UIView setAnimationDuration:0.15]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(popStep2Complete)]; 
    v.frame = CGRectMake(110, 110, 100, 100); 
    [UIView commitAnimations]; 
} 

- (void)popStep2Complete { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [UIView setAnimationDuration:0.15]; 
    v.frame = CGRectMake(100, 100, 120, 120); 
    [UIView commitAnimations]; 
} 

उत्तर

77
- (void) attachPopUpAnimation 
{ 
    CAKeyframeAnimation *animation = [CAKeyframeAnimation 
     animationWithKeyPath:@"transform"]; 

    CATransform3D scale1 = CATransform3DMakeScale(0.5, 0.5, 1); 
    CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1); 
    CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1); 
    CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1); 

    NSArray *frameValues = [NSArray arrayWithObjects: 
     [NSValue valueWithCATransform3D:scale1], 
     [NSValue valueWithCATransform3D:scale2], 
     [NSValue valueWithCATransform3D:scale3], 
     [NSValue valueWithCATransform3D:scale4], 
     nil]; 
    [animation setValues:frameValues]; 

    NSArray *frameTimes = [NSArray arrayWithObjects: 
     [NSNumber numberWithFloat:0.0], 
     [NSNumber numberWithFloat:0.5], 
     [NSNumber numberWithFloat:0.9], 
     [NSNumber numberWithFloat:1.0], 
     nil];  
    [animation setKeyTimes:frameTimes]; 

    animation.fillMode = kCAFillModeForwards; 
    animation.removedOnCompletion = NO; 
    animation.duration = .2; 

    [self.layer addAnimation:animation forKey:@"popup"]; 
} 
+0

यह कहां जाता है? मेरे मूल दृश्य या मेरे UIAlertView में? – Moshe

+0

'UIView' का कोई उप-वर्ग। इस मामले में कस्टम 'UIAlertView' जैसी कक्षा। – zoul

+0

एनीमेशन के चारों ओर दूसरी बार फायरिंग नहीं थी, नील कुंजी सेट करने के लिए मेरे लिए समस्या तय की गई: [self.view.layer addAnimation: एनीमेशन forKey: nil]; – amleszk

5

एक बात: इस तरह बहु-चरण एनिमेशन यदि आप एक CAKeyframeAnimation एकाधिक के बजाय UIView कतारबद्ध एनिमेशन का उपयोग बहुत आसान कर रहे हैं।

+3

धन्यवाद, लेकिन क्या आप कृपया अपना उत्तर हटा दें और इसे एक टिप्पणी के रूप में शामिल करें क्योंकि यह प्रश्न अब उत्तर के रूप में दिखाई देता है। – RunLoop

+9

नहीं, मुझे नहीं, क्षमा करेंगी। जबकि मुझे एहसास है कि मेरा जवाब वह नहीं है जिसे आप सुनना चाहते थे और केवल आंशिक समाधान है, यह आईएमओ एक वैध उत्तर है क्योंकि यह आपके द्वारा पोस्ट किए गए कोड की तुलना में समस्या का एक बेहतर तरीका है। –

7

डेलैकनर की पोस्ट के सूचक को सबसे अच्छा प्रारंभिक मिला है। अर्द्ध पारदर्शी परत रंग

  • कुछ अल्फा फीका-इन/आउट
    1. गोल किनारों, सीमा जोड़ने, और, और: मैं केवल करने के लिए वास्तव में नकल UIAlertView कुछ चीजें कोशिश कर लोगों के लिए की पेशकश करेगा के रूप में कुछ हद तक ब्लॉक के साथ redoing
    2. मैं भी प्रारंभिक 1.1 पैमाने बाहर वह बहुत बड़ी अधिक सही, 1.05 लग रहा था पता चलता है नेत्रहीन मेरे लिए ज्यादातर मामलों

    कोड में पाया नवीनतम iOS toolchain के साथ अधिक संक्षिप्त:

    self.layer.cornerRadius = 10.0; 
    [self.layer setMasksToBounds:YES]; 
    self.layer.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.60].CGColor; 
    self.layer.borderColor = [UIColor whiteColor].CGColor; 
    self.layer.borderWidth = 1.1; 
    if (self.hidden == YES) { // swoop in if coming from hidden, otherwise pulse in-place 
        self.transform = CGAffineTransformMakeScale(0.6, 0.6); 
    } 
    self.hidden = NO; 
    [UIView animateWithDuration:0.2 
           animations:^{ 
            self.transform = CGAffineTransformMakeScale(1.05, 1.05); 
            self.alpha = 0.8; 
           } 
           completion:^(BOOL finished){ 
            [UIView animateWithDuration:1/15.0 
                animations:^{ 
                 self.transform = CGAffineTransformMakeScale(0.9, 0.9); 
                 self.alpha = 0.9; 
                } 
                completion:^(BOOL finished) { 
                 [UIView animateWithDuration:1/7.5 
                     animations:^{ 
                     self.transform = CGAffineTransformIdentity;                
                     self.alpha = 1.0; 
                     } 
                 ]; 
                } 
            ]; 
           } 
    ]; 
    
  • संबंधित मुद्दे