Autoresizing bei UILabel funktioniert nicht einwandfrei

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Autoresizing bei UILabel funktioniert nicht einwandfrei

    Guten Tag zusammen,

    ich habe ein Problem beim Autoresizing eines UILabel!
    Hier erstmal mein Code:

    Quellcode

    1. #import <UIKit/UIKit.h>
    2. @interface Gutscheinuebersicht_Karte : UIView
    3. {
    4. //Button
    5. UIButton *btn_karte;
    6. //Headline
    7. UILabel *la_headline;
    8. }
    9. //Initialisieren
    10. - (id)initWithFrame:(CGRect)frame
    11. setHeadline:(NSString *)headline
    12. setImage:(NSString *)image
    13. setAktion:(NSString *)aktion
    14. setZusatztext:(NSString *)zusatztext;
    15. @end
    Alles anzeigen


    Quellcode

    1. #import "Gutscheinuebersicht_Karte.h"
    2. @implementation Gutscheinuebersicht_Karte
    3. //Initialisieren
    4. - (id)initWithFrame:(CGRect)frame
    5. setHeadline:(NSString *)headline
    6. setImage:(NSString *)image
    7. setAktion:(NSString *)aktion
    8. setZusatztext:(NSString *)zusatztext
    9. {
    10. self = [super initWithFrame:frame];
    11. if (self) {
    12. self.autoresizesSubviews = YES;
    13. //Button
    14. btn_karte = [UIButton buttonWithType:UIButtonTypeCustom];
    15. btn_karte.frame = CGRectMake(0.0, 0.0, frame.size.width, frame.size.height);
    16. [btn_karte setBackgroundImage:[UIImage imageWithContentsOfFile:[Bilderimport bilderzeichniss:@"Grafiken/Gutscheine" Filename:@"bg_gutschein_blank.png"]] forState:UIControlStateNormal];
    17. [btn_karte setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
    18. [self addSubview:btn_karte];
    19. //Headline
    20. la_headline = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
    21. la_headline.backgroundColor = [UIColor grayColor];
    22. la_headline.font = [UIFont boldSystemFontOfSize:16.0];
    23. la_headline.textColor = [UIColor blackColor];
    24. la_headline.textAlignment = NSTextAlignmentCenter;
    25. la_headline.text = headline;
    26. [la_headline setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
    27. [self addSubview:la_headline];
    28. }
    29. return self;
    30. }
    31. @end
    Alles anzeigen


    Nun der Animationscode:

    Quellcode

    1. //Rotate
    2. [UIView animateWithDuration:animation_duration_stapel_oeffnen/2
    3. delay: 0.0
    4. options: UIViewAnimationOptionCurveLinear
    5. animations:^{
    6. karte_2.transform = CGAffineTransformMakeRotation(0 * M_PI / 180);
    7. karte_3.transform = CGAffineTransformMakeRotation(0 * M_PI / 180);
    8. karte_4.transform = CGAffineTransformMakeRotation(0 * M_PI / 180);
    9. }
    10. completion:^(BOOL finished){
    11. //Kreuz + Position + Alpha
    12. [UIView animateWithDuration:animation_duration_stapel_oeffnen/2
    13. delay: 0.0
    14. options: UIViewAnimationOptionCurveLinear
    15. animations:^{
    16. //Kreuz
    17. iV_kreuz.alpha = 1.0;
    18. //Position
    19. karte_1.frame = CGRectMake((self.frame.size.width/2 - gutschein_width_klein)/2,
    20. (self.frame.size.height/2 - gutschein_height_klein)/2,
    21. gutschein_width_klein,
    22. gutschein_height_klein);
    23. karte_2.frame = CGRectMake(self.frame.size.width - gutschein_width_klein - (self.frame.size.width/2 - gutschein_width_klein)/2,
    24. (self.frame.size.height/2 - gutschein_height_klein)/2,
    25. gutschein_width_klein,
    26. gutschein_height_klein);
    27. karte_3.frame = CGRectMake((self.frame.size.width/2 - gutschein_width_klein)/2,
    28. self.frame.size.height - gutschein_height_klein - (self.frame.size.height/2 - gutschein_height_klein)/2,
    29. gutschein_width_klein,
    30. gutschein_height_klein);
    31. karte_4.frame = CGRectMake(self.frame.size.width - gutschein_width_klein - (self.frame.size.width/2 - gutschein_width_klein)/2,
    32. self.frame.size.height - gutschein_height_klein - (self.frame.size.height/2 - gutschein_height_klein)/2,
    33. gutschein_width_klein,
    34. gutschein_height_klein);
    35. //Alpha
    36. karte_2.alpha = 1.0;
    37. karte_3.alpha = 1.0;
    38. karte_4.alpha = 1.0;
    39. }
    40. completion:^(BOOL finished){
    41. //TapGesture
    42. [self removeGestureRecognizer:tapGesture];
    43. //PinchGesture
    44. pinch_uebersicht = TRUE;
    45. //View
    46. karte_1.userInteractionEnabled = YES;
    47. karte_2.userInteractionEnabled = YES;
    48. karte_3.userInteractionEnabled = YES;
    49. karte_4.userInteractionEnabled = YES;
    50. }];
    51. }];
    Alles anzeigen


    Mein Problem:
    Die Größe und Position des View "karte_1 - karte_4" passt sich während der Animation an. Der Button "btn_karte" passt sich auch wie geplant an.
    Nur das Label "la_headline" springt auf einemal an den linken Rand und ändert direkt die Größe, wie in den Screenshots zu sehen.
    Woran kann das liegen?

    Hoffe, dass Ihr mir helfen könnt.

    Gruß
    kruemel1770
    Dateien
    • IMG_0019.PNG

      (111,19 kB, 238 mal heruntergeladen, zuletzt: )
    • IMG_0020.PNG

      (180,94 kB, 227 mal heruntergeladen, zuletzt: )
    • IMG_0021.PNG

      (195,72 kB, 243 mal heruntergeladen, zuletzt: )