क्या छवियों के एक सेट के साथ UIButton पृष्ठभूमि छवि दृश्य को एनिमेट करने का कोई तरीका है?एनीमेशन UIButton पृष्ठभूमि छवि
मैंने छवि दृश्य संपत्ति के साथ ऐसा करने में कामयाब रहा है, लेकिन समकक्ष पृष्ठभूमि संपत्ति नहीं मिल सका।
10x
क्या छवियों के एक सेट के साथ UIButton पृष्ठभूमि छवि दृश्य को एनिमेट करने का कोई तरीका है?एनीमेशन UIButton पृष्ठभूमि छवि
मैंने छवि दृश्य संपत्ति के साथ ऐसा करने में कामयाब रहा है, लेकिन समकक्ष पृष्ठभूमि संपत्ति नहीं मिल सका।
10x
को बदलने के लिए एक बटन उस बात के लिए छवि, या टेक्स्ट backround - आप विशेष UIControlState ... यानी हाइलाइट, चयनित के लिए इसे बदलने की जरूरत है, विकलांग
उपयोग
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
मुझे यकीन नहीं है कि क्या आप उन्हें एनिमेट कर सकते हैं, मैंने कभी कोशिश नहीं की है। यदि आप उन्हें एनिमेट नहीं कर सकते हैं, तो आप एक पारदर्शी बटन के पीछे UIImageView डाल सकते हैं और इसके बजाय छवियों को एनिमेट कर सकते हैं - बस एक विचार।
हां यह संभव है। NSTimer का उपयोग करें,
एनएसटीमर * myTimer = [NSTimer शेड्यूल टाइमर विथटाइम इंटरवल: 5.00 लक्ष्य: स्वयं चयनकर्ता: @ चयनकर्ता (परिवर्तन छवि) userInfo: nil repeats: हाँ];
तो, विधि
- (void)changeImage
{
static int counter = 0;
if([bannerArray count] == counter)
{
counter = 0;
}
[button setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:bannerArray[counter]]]] forState:UIControlStateNormal];
counter++;
}
इस प्रकार है, यह मेरे लिए काम किया। लेकिन फ्लिप आदि जैसे एनीमेशन को जोड़ने की जरूरत है। आशा है कि यह आपकी ज़रूरत में मदद करने का एक तरीका भी है।
आप एक UIButton
जिस तरह से आप एक UIImageView
इस तरह चेतन चेतन कर सकते हैं ...
-(void) addAnimationToButton:(UIButton*) button{
UIImageView* animationView = [button imageView];
NSArray* animations=[NSArray arrayWithObjects:
[UIImage imageNamed:@"sprite1.png"],
[UIImage imageNamed:@"sprite2.png"],
[UIImage imageNamed:@"sprite2.png"],
//and so on if you need more
nil];
CGFloat animationDuration = 2.0;
[animationView setAnimationImages:animations];
[animationView setAnimationDuration:animationDuration];
[animationView setAnimationRepeatCount:0]; //0 is infinite
}
और तुम इस तरह इसका इस्तेमाल:
[self addAnimationToButton:yourButton];
[[yourButton imageView] startAnimating]; //or stopAnimating
यहाँ मैं क्या किया है (एक UIButton उपवर्ग के अंदर):
सेट बटन छवियों, नियमित रूप से की तरह:
[self setBackgroundImage:[[UIImage imageNamed:@"button"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateNormal];
[self setBackgroundImage:[[UIImage imageNamed:@"button_pressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateHighlighted];
अवहेलना पर प्रकाश डाला:
- (void)setHighlighted:(BOOL)highlighted {
[UIView transitionWithView:self duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowAnimatedContent animations:^{
[super setHighlighted:highlighted];
} completion:nil];
}
यह एक शानदार समाधान है –
मैं एक पारदर्शी बटन के पीछे एक UIImageView रख दिया है। थोड़ा हैकी, लेकिन मैं क्या कह सकता हूं - यह काम किया! 10x – Rizon