我正在网上寻找,但找不到明确的答案。您认为使这些功能静态化的最佳方法是什么?
CGRect ScreenRect = [[UIScreen mainScreen] bounds];
CGFloat screenwidth = screenRect.size.width;
CGFloat screenHeight = 64;
我需要在我的 UIView 类中多次调用它们并且无法弄清楚如何以干净优雅的方式实现它?
示例实际代码
-(id)initializeNetworkDetect:(NSString *)detectMessage {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = 64;
networkView = [self initWithFrame:CGRectMake(0, -220, screenWidth, screenHeight)];
if (networkView) {
networkView.backgroundColor = BCKNETWORKVIEW;
labelNetwork = [[UILabel alloc] init];
[labelNetwork setFrame:CGRectMake(0, 4, 320, 30)];
[labelNetwork setFont:[UIFont boldSystemFontOfSize:11]];
[labelNetwork setBackgroundColor : [UIColor clearColor]];
[labelNetwork setTextColor: [UIColor whiteColor]];
[labelNetwork setAdjustsFontSizeToFitWidth:TRUE];
[labelNetwork setText:detectMessage];
labelNetwork.textAlignment = NSTextAlignmentCenter;
labelNetwork.lineBreakMode = NSLineBreakByWordWrapping;
labelNetwork.numberOfLines = 2;
[networkView addSubview:labelNetwork];
NSString *successAlertString = [[NSString alloc] init];
successAlertString = detectMessage;
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endTapping)];
tapGesture.cancelsTouchesInView = NO;
[self setUserInteractionEnabled:YES];
[self addGestureRecognizer:tapGesture];
}
return self;
}
-(void)showNetworkMessage {
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = 64;
screenRect = CGRectMake(0, 0, screenWidth, screenHeight);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
self.frame = screenRect;
[UIView commitAnimations];
}
-(void)setHideAnimationNetwork{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = 64;
screenRect = CGRectMake(0, -220, screenWidth, screenHeight);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(deleteAnimation)];
self.frame = screenRect;
[UIView commitAnimations];
}