Selbstgebauter ActivityView funktioniert nicht mehr

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

  • Selbstgebauter ActivityView funktioniert nicht mehr

    Hi,

    ich habe vor ewigen Zeiten mal einen sehr universellen und praktischen ActivityView gebastelt. Leider kann ich bei dem unter iOS6 und iOS7 den Cancel-Button nicht mehr betätigen. Es sieht so aus als würden die Touches nicht ausgewertet denn die ibAction wird nicht aufgerufen.

    Hat jemand eine Idee warum das so ist?

    Quellcode

    1. @interface ActivityView ()
    2. @property (nonatomic, strong) UIView *backgroundView,*parentView;
    3. @property (nonatomic, strong) UIActivityIndicatorView *activityView;
    4. @property (nonatomic, strong) UIProgressView *progressView;
    5. @property (nonatomic, strong) UIButton *cancelButton;
    6. @property (nonatomic, strong) UILabel *titleLabel,*centerLabel;
    7. @property (nonatomic, assign) BOOL canceled;
    8. @property (nonatomic, assign) SEL cancelSelector;
    9. @property (nonatomic, assign) NSInteger orientation;
    10. @end
    11. @implementation ActivityView
    12. @synthesize delegate,titleLabel,centerLabel,backgroundView,activityView,progressView,cancelButton,parentView,canceled,cancelSelector,orientation;
    13. #define CANCELBUTTON_HEIGHT (29)
    14. #define YOFFSET (8)
    15. #define BOTTOM_OFFSET (20)
    16. #define LEFT_OFFSET (20)
    17. #define TITLE_HEIGHT (22)
    18. -(id)initWithParentView:(UIView *)parent ShowProgress:(BOOL)showProgress CancelButton:(BOOL)doCancel
    19. {
    20. if(!parent) {
    21. AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
    22. parent=appDelegate.window;
    23. }
    24. orientation=[UIApplication sharedApplication].statusBarOrientation;
    25. if(!orientation)
    26. orientation=UIInterfaceOrientationLandscapeRight;
    27. CGRect frame=[parent frame];
    28. self=[self initWithFrame:frame];
    29. if(self)
    30. {
    31. self.parentView=parent;
    32. self.userInteractionEnabled=YES;
    33. self.backgroundColor=[UIColor clearColor];
    34. self.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    35. self.alpha=0;
    36. CGFloat width = 200.f;
    37. CGFloat height = 200.f;
    38. if(![self isIPad]) {
    39. width=140;
    40. height=140;
    41. self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] ;
    42. }
    43. else {
    44. self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    45. }
    46. if(showProgress)
    47. {
    48. progressView=[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    49. }
    50. else
    51. self.progressView=nil;
    52. if(doCancel)
    53. {
    54. width+=CANCELBUTTON_HEIGHT+YOFFSET;
    55. height+=CANCELBUTTON_HEIGHT+YOFFSET;
    56. }
    57. CGRect centeredFrame=CGRectMake(round(self.frame.size.width/2 - width/2),
    58. round(self.frame.size.height/2 - height/2),
    59. width,
    60. height);
    61. /* backgroundView */
    62. backgroundView = [[UIView alloc] initWithFrame:centeredFrame];
    63. backgroundView.opaque = NO;
    64. backgroundView.alpha = 1.0;
    65. backgroundView.backgroundColor=[UIColor colorWithRed:1.0/255.0 green:103.0/255.0 blue:233.0/255.0 alpha:0.9];
    66. backgroundView.layer.cornerRadius = 10;
    67. backgroundView.userInteractionEnabled = YES;
    68. backgroundView.autoresizesSubviews = NO;
    69. backgroundView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    70. /* activityView */
    71. activityView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - activityView.frame.size.width/2),
    72. round(height/2 - activityView.frame.size.height/2),
    73. activityView.frame.size.width,
    74. activityView.frame.size.height);
    75. [backgroundView addSubview:activityView];
    76. [activityView startAnimating];
    77. // progressView */
    78. if(progressView)
    79. {
    80. if(doCancel)
    81. {
    82. progressView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
    83. round(backgroundView.bounds.size.height - progressView.frame.size.height-YOFFSET - CANCELBUTTON_HEIGHT- BOTTOM_OFFSET),
    84. width-2*LEFT_OFFSET,
    85. progressView.frame.size.height);
    86. }
    87. else
    88. {
    89. progressView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
    90. round(backgroundView.bounds.size.height - progressView.frame.size.height-BOTTOM_OFFSET),
    91. width-2*LEFT_OFFSET,
    92. progressView.frame.size.height);
    93. }
    94. [backgroundView addSubview:progressView];
    95. }
    96. if(doCancel)
    97. {
    98. self.cancelButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    99. cancelButton.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
    100. round(backgroundView.bounds.size.height - CANCELBUTTON_HEIGHT-BOTTOM_OFFSET),
    101. width-2*LEFT_OFFSET,CANCELBUTTON_HEIGHT);
    102. [cancelButton setTitle:NSLocalizedString(@"Cancel", @"ActivitiyView Cancel button text") forState:UIControlStateNormal];
    103. [cancelButton addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    104. [cancelButton setBackgroundImage:[UIImage imageNamed:@"cancel_black.png"] forState:UIControlStateNormal];
    105. [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    106. [backgroundView addSubview:cancelButton];
    107. }
    108. titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 20, backgroundView.frame.size.width-2*LEFT_OFFSET,TITLE_HEIGHT)];
    109. if([self isIPad])
    110. titleLabel.font=[UIFont boldSystemFontOfSize:20];
    111. else
    112. titleLabel.font=[UIFont boldSystemFontOfSize:14];
    113. titleLabel.backgroundColor=[UIColor clearColor];
    114. titleLabel.textColor=[UIColor whiteColor];
    115. titleLabel.textAlignment=NSTextAlignmentCenter;
    116. [backgroundView addSubview:titleLabel];
    117. centerLabel=[[UILabel alloc] initWithFrame:activityView.frame];
    118. centerLabel.font=[UIFont boldSystemFontOfSize:activityView.frame.size.height];
    119. centerLabel.backgroundColor=[UIColor clearColor];
    120. centerLabel.textColor=[UIColor whiteColor];
    121. centerLabel.textAlignment=NSTextAlignmentCenter;
    122. [backgroundView addSubview:centerLabel];
    123. switch (orientation) {
    124. case 3:
    125. backgroundView.transform=CGAffineTransformMakeRotation(90.0*3.1415927/180.0);
    126. break;
    127. case 4:
    128. backgroundView.transform=CGAffineTransformMakeRotation(270*3.1415927/180.0);
    129. break;
    130. case 2:
    131. backgroundView.transform=CGAffineTransformMakeRotation(180*3.1415927/180.0);
    132. break;
    133. default:
    134. break;
    135. }
    136. [self addSubview:backgroundView];
    137. }
    138. return self;
    139. }
    140. -(void)cancelButtonPressed
    141. {
    142. self.canceled=YES;
    143. if(delegate){
    144. [delegate didCancel:self];
    145. }
    146. [[NSNotificationCenter defaultCenter] postNotificationName:ACTIVITYCANCEL_NOTIFICATION object:nil];
    147. }
    148. - (void)show
    149. {
    150. if (![self superview])
    151. {
    152. [parentView addSubview:self];
    153. }
    154. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hide) object:nil];
    155. [UIView beginAnimations:nil context:NULL];
    156. [UIView setAnimationDuration:0.3];
    157. self.alpha = 1;
    158. [UIView commitAnimations];
    159. }
    Alles anzeigen


    Ich rufe das show mit parentView von nil auf, so dass vom AppDelegate das window benutzt wird. Liegt es eventuell daran dass das keine Touches verarbeitet?
    Ich weiß, dass der Code zu 99% längst überholt ist aber ich habe jetzt gerade echt wenig Zeit das komlett neu zu schreiben. Wenn es sich mit einer kleinen Änderung erstmal so weiter benutzen liesse würde mir das ziemlich helfen

    Danke

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)
  • Leider nein, die Frames sehen alle soweit korrekt aus

    2014-03-16 17:27:55.047 BackgroundView: {{266, 394}, {237, 237}}
    2014-03-16 17:27:55.048 Activity: {{100, 100}, {37, 37}}
    2014-03-16 17:27:55.049 CancelButton: {{20, 188}, {197, 29}}
    2014-03-16 17:27:55.050 self: {{0, 0}, {768, 1024}}

    Gruß

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)