// // UIView+Decoder.m // #import "UIView+Decoder.h" @implementation UIView(Background) - (void)setBackgroundImage { self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mainbg.png"]]; // self.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; } @end @implementation UIView (Remixes) - (void) changeFrame:(CGRect)frame overTimeInterval:(double)timeInterval { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:timeInterval]; [self setFrame:frame]; [UIView commitAnimations]; } - (void)changeFrame:(CGRect)theFrame overTimeInterval:(double)timeInterval animationCurve:(UIViewAnimationCurve)animationCurve { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:timeInterval]; [UIView setAnimationCurve:animationCurve]; [self setFrame:theFrame]; [UIView commitAnimations]; } - (void) fadeIn { self.alpha = 0.0; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; self.alpha = 1.0; [UIView commitAnimations]; } - (void) fadeOut { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; self.alpha = 0.0; [UIView commitAnimations]; } - (void) fadeFrom:(float)from to:(float)to over:(float)seconds { self.alpha = from; [UIView beginAnimations:@"Sweet!" context:NULL]; [UIView setAnimationDuration:seconds]; self.alpha = to; [UIView commitAnimations]; } - (void) fadeOutThenCallSelector:(SEL)selector delegate:(id)delegate { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:delegate]; [UIView setAnimationDidStopSelector:selector]; self.alpha = 0.0; [UIView commitAnimations]; } - (void) removeSubviewWithTagIfExists:(int)theTag { if([self viewWithTag:theTag]) [[self viewWithTag:theTag] removeFromSuperview]; } - (NSMutableDictionary *)fullDescription { NSDictionary *frame = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat:self.frame.origin.x], @"x", [NSNumber numberWithFloat:self.frame.origin.y], @"y", [NSNumber numberWithFloat:self.frame.size.width], @"width", [NSNumber numberWithFloat:self.frame.size.height], @"height", nil]; NSMutableDictionary *description = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger:(NSInteger)self], @"address", NSStringFromClass([self class]), @"className", frame, @"frame", [NSNumber numberWithInteger:[self tag]], @"tag", [self valueForKeyPath:@"subviews.fullDescription"], @"subviews", nil]; if ([self respondsToSelector:@selector(text)]) { [description setValue:[self performSelector:@selector(text)] forKey:@"text"]; } if ([self respondsToSelector:@selector(title)]) { [description setValue:[self performSelector:@selector(title)] forKey:@"title"]; } if ([self respondsToSelector:@selector(currentTitle)]) { [description setValue:[self performSelector:@selector(currentTitle)] forKey:@"currentTitle"]; } return description; } - (UIViewController *) firstAvailableUIViewController { // convenience function for casting and to "mask" the recursive function return (UIViewController *)[self traverseResponderChainForUIViewController]; } - (id) traverseResponderChainForUIViewController { id nextResponder = [self nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) { return nextResponder; } else if ([nextResponder isKindOfClass:[UIView class]]) { return [nextResponder traverseResponderChainForUIViewController]; } else { return nil; } } @end