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?
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
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
- @interface ActivityView ()
- @property (nonatomic, strong) UIView *backgroundView,*parentView;
- @property (nonatomic, strong) UIActivityIndicatorView *activityView;
- @property (nonatomic, strong) UIProgressView *progressView;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) UILabel *titleLabel,*centerLabel;
- @property (nonatomic, assign) BOOL canceled;
- @property (nonatomic, assign) SEL cancelSelector;
- @property (nonatomic, assign) NSInteger orientation;
- @end
- @implementation ActivityView
- @synthesize delegate,titleLabel,centerLabel,backgroundView,activityView,progressView,cancelButton,parentView,canceled,cancelSelector,orientation;
- #define CANCELBUTTON_HEIGHT (29)
- #define YOFFSET (8)
- #define BOTTOM_OFFSET (20)
- #define LEFT_OFFSET (20)
- #define TITLE_HEIGHT (22)
- -(id)initWithParentView:(UIView *)parent ShowProgress:(BOOL)showProgress CancelButton:(BOOL)doCancel
- {
- if(!parent) {
- AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
- parent=appDelegate.window;
- }
- orientation=[UIApplication sharedApplication].statusBarOrientation;
- if(!orientation)
- orientation=UIInterfaceOrientationLandscapeRight;
- CGRect frame=[parent frame];
- self=[self initWithFrame:frame];
- if(self)
- {
- self.parentView=parent;
- self.userInteractionEnabled=YES;
- self.backgroundColor=[UIColor clearColor];
- self.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
- self.alpha=0;
- CGFloat width = 200.f;
- CGFloat height = 200.f;
- if(![self isIPad]) {
- width=140;
- height=140;
- self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] ;
- }
- else {
- self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- }
- if(showProgress)
- {
- progressView=[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
- }
- else
- self.progressView=nil;
- if(doCancel)
- {
- width+=CANCELBUTTON_HEIGHT+YOFFSET;
- height+=CANCELBUTTON_HEIGHT+YOFFSET;
- }
- CGRect centeredFrame=CGRectMake(round(self.frame.size.width/2 - width/2),
- round(self.frame.size.height/2 - height/2),
- width,
- height);
- /* backgroundView */
- backgroundView = [[UIView alloc] initWithFrame:centeredFrame];
- backgroundView.opaque = NO;
- backgroundView.alpha = 1.0;
- backgroundView.backgroundColor=[UIColor colorWithRed:1.0/255.0 green:103.0/255.0 blue:233.0/255.0 alpha:0.9];
- backgroundView.layer.cornerRadius = 10;
- backgroundView.userInteractionEnabled = YES;
- backgroundView.autoresizesSubviews = NO;
- backgroundView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
- /* activityView */
- activityView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - activityView.frame.size.width/2),
- round(height/2 - activityView.frame.size.height/2),
- activityView.frame.size.width,
- activityView.frame.size.height);
- [backgroundView addSubview:activityView];
- [activityView startAnimating];
- // progressView */
- if(progressView)
- {
- if(doCancel)
- {
- progressView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
- round(backgroundView.bounds.size.height - progressView.frame.size.height-YOFFSET - CANCELBUTTON_HEIGHT- BOTTOM_OFFSET),
- width-2*LEFT_OFFSET,
- progressView.frame.size.height);
- }
- else
- {
- progressView.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
- round(backgroundView.bounds.size.height - progressView.frame.size.height-BOTTOM_OFFSET),
- width-2*LEFT_OFFSET,
- progressView.frame.size.height);
- }
- [backgroundView addSubview:progressView];
- }
- if(doCancel)
- {
- self.cancelButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
- cancelButton.frame = CGRectMake(round(backgroundView.bounds.size.width/2 - (width-2*LEFT_OFFSET)/2),
- round(backgroundView.bounds.size.height - CANCELBUTTON_HEIGHT-BOTTOM_OFFSET),
- width-2*LEFT_OFFSET,CANCELBUTTON_HEIGHT);
- [cancelButton setTitle:NSLocalizedString(@"Cancel", @"ActivitiyView Cancel button text") forState:UIControlStateNormal];
- [cancelButton addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
- [cancelButton setBackgroundImage:[UIImage imageNamed:@"cancel_black.png"] forState:UIControlStateNormal];
- [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [backgroundView addSubview:cancelButton];
- }
- titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 20, backgroundView.frame.size.width-2*LEFT_OFFSET,TITLE_HEIGHT)];
- if([self isIPad])
- titleLabel.font=[UIFont boldSystemFontOfSize:20];
- else
- titleLabel.font=[UIFont boldSystemFontOfSize:14];
- titleLabel.backgroundColor=[UIColor clearColor];
- titleLabel.textColor=[UIColor whiteColor];
- titleLabel.textAlignment=NSTextAlignmentCenter;
- [backgroundView addSubview:titleLabel];
- centerLabel=[[UILabel alloc] initWithFrame:activityView.frame];
- centerLabel.font=[UIFont boldSystemFontOfSize:activityView.frame.size.height];
- centerLabel.backgroundColor=[UIColor clearColor];
- centerLabel.textColor=[UIColor whiteColor];
- centerLabel.textAlignment=NSTextAlignmentCenter;
- [backgroundView addSubview:centerLabel];
- switch (orientation) {
- case 3:
- backgroundView.transform=CGAffineTransformMakeRotation(90.0*3.1415927/180.0);
- break;
- case 4:
- backgroundView.transform=CGAffineTransformMakeRotation(270*3.1415927/180.0);
- break;
- case 2:
- backgroundView.transform=CGAffineTransformMakeRotation(180*3.1415927/180.0);
- break;
- default:
- break;
- }
- [self addSubview:backgroundView];
- }
- return self;
- }
- -(void)cancelButtonPressed
- {
- self.canceled=YES;
- if(delegate){
- [delegate didCancel:self];
- }
- [[NSNotificationCenter defaultCenter] postNotificationName:ACTIVITYCANCEL_NOTIFICATION object:nil];
- }
- - (void)show
- {
- if (![self superview])
- {
- [parentView addSubview:self];
- }
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hide) object:nil];
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:0.3];
- self.alpha = 1;
- [UIView commitAnimations];
- }
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
Pre-Kaffee-Posts sind mit Vorsicht zu geniessen