`
jsntghf
  • 浏览: 2572271 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

写信息中收信人高度可变的实现

    博客分类:
  • iOS
阅读更多

添加收信人后,收信人区域的高度会自动增长,删除收信人后,收信人区域的高度会相应降低,主要方法如下:

-(void)refreshReceiverView:(int)flag
{	
	if(flag == MSGV_DEL_CONTACT)
	{
		NSMutableArray *temA = [[NSMutableArray alloc] init]; 
		for(GPMsgReceiverView *msgV in [toContainerView subviews])
		{
			[temA addObject:msgV];
			[msgV removeFromSuperview];
		}
		
		receiverRowIndex = 0;
		indexOfFirstNewLine = 0;
		toContainerView.frame = CGRectMake(0.0, 0.0, 320, 44.0+receiverRowIndex*44.0);
		[mainView reloadData];
		
		for(GPMsgReceiverView *msgV1 in temA)
		{
			int count = [[toContainerView subviews] count];
			int length = count - indexOfFirstNewLine;
			
			NSArray *lineCheckArray = [[toContainerView subviews] objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(indexOfFirstNewLine, length)]];
			
			int totalWidth = 0;
			int oldWidth = 0;
			for(GPMsgReceiverView *mv in lineCheckArray)
			{
				totalWidth += mv.frame.size.width;
				oldWidth += mv.frame.size.width;  //some line, from the first to the last
			}
			totalWidth += msgV1.frame.size.width; //check if add current beyond the width
			
			if(totalWidth < 250)
			{
				msgV1.center = CGPointMake(oldWidth + msgV1.frame.size.width/2 + 5.0, 22.0+receiverRowIndex*44.0);
			}
			else 
			{
				indexOfFirstNewLine = [[toContainerView subviews] count];  //-1 then +1
				++receiverRowIndex;
				
				msgV1.center = CGPointMake(msgV1.frame.size.width/2 + 5.0, 22.0+receiverRowIndex*44.0);
			}
			[toContainerView addSubview:msgV1];
		}
		[temA release];
		toContainerView.frame = CGRectMake(0.0, 0.0, 320, 44.0+receiverRowIndex*44.0);
	}
	if(flag == MSGV_ADD_CONTACT)
	{
		toContainerView.frame = CGRectMake(0.0, 0.0, 320, 44.0+receiverRowIndex*44.0);
	}
	[mainView reloadData];
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics