मैंने देखा कि जब मैं एनीमेशन ब्लॉक में यूआईएलएबल की सीमाओं को बदलता हूं तो यह केवल तभी काम करता है जब मैं आकार बढ़ाता हूं, जब मैं आकार कम करता हूं तो यूलाबेल सिर्फ आकार बदलता है लेकिन एनिमेट नहीं करता है। UILabel को एक सादे UIView कार्यों के साथ लक्षित के रूप में बदलना।आकार बढ़ाने पर केवल UILabel की सीमाओं पर एनिमेशन क्यों काम कर रहे हैं?
नोट: सामग्री को बदलना UILabelContentModeScaleToFill को UILabel की MOD संपत्ति को इस समस्या को हल करता है, लेकिन मुझे अभी भी समझ में नहीं आता है कि सामग्री को बदले बिना आकार बढ़ाने के दौरान यह क्यों काम करता है।
#import "FooView.h"
@interface FooView()
@property (strong, nonatomic) UILabel *label;
@property (assign, nonatomic) BOOL resized;
@end
@implementation FooView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor lightGrayColor];
self.label = [[UILabel alloc] initWithFrame:(CGRect){0, 0, frame.size}];
self.label.backgroundColor = [UIColor greenColor];
[self addSubview:self.label];
_resized = false;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeSize)];
tapRecognizer.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapRecognizer];
}
return self;
}
- (void)changeSize {
[UIView animateWithDuration:0.8
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect bounds = self.label.bounds;
if (self.resized) {
bounds.size.height *= 2;
bounds.size.width *= 2;
} else {
bounds.size.width /= 2;
bounds.size.height /= 2;
}
self.label.bounds = bounds;
}
completion:^(BOOL finished) {
self.resized = !self.resized;
}];
}
@end
आपके पास यहां जवाब है: http://stackoverflow.com/questions/3298764/animating-uilabel-size-decrease – Amit
@ amit3117 कोई यह नहीं बताता है कि क्यों, और मैं फ्रेम को फ्रेम नहीं बदल रहा हूं – peko
मैं बस अपना कोड सेटअप करता हूं और सोच रहा हूं कि यदि आप एक ही प्रभाव को देख रहे हैं, तो मैं एनीमेशन के साथ बढ़ता हूं, लेकिन जब आप फिर से टैप करते हैं तो यह छोटे आकार में "स्नैप" करता है, हालांकि मुझे लगता है कि मेरा केंद्रित टेक्स्ट वापस एनिमेट कर रहा है जैसा कि यह बढ़ रहा था .... बस पृष्ठभूमि रंग को केवल छोटे लेबल – rezand