我有这个代码用于增加图像的高度。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
touchStart = [[touches anyObject] locationInView:self.image];
touchStart2 = [[touches anyObject] locationInView:self.tableView];
isResizingLR = ( self.image.bounds.size.height - touchStart.y < kResizeThumbSize );
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint touchPoint = [[touches anyObject] locationInView:self.image];
CGPoint previous=[[touches anyObject]previousLocationInView:self.image];
float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;
if (isResizingLR) {
self.image.frame = CGRectMake(self.image.frame.origin.x, self.image.frame.origin.y, self.image.frame.size.width, touchPoint.y + deltaWidth);
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x ,self.tableView.frame.origin.y + deltaHeight, self.tableView.frame.size.width, self.tableView.frame.size.height - deltaHeight );
self.viewTitle.frame = CGRectMake(self.viewTitle.frame.origin.x ,self.viewTitle.frame.origin.y + deltaHeight, self.viewTitle.frame.size.width, self.viewTitle.frame.size.height);
}
}
我想为minimHeight = 100和maximHeight = 300设置条件; 我怎样才能做到这一点? 我已经尝试过了:
if (isResizingLR) {
if (self.image.frame.size.height >100 && self.image.frame.size.height <300) {
self.image.frame = CGRectMake(self.image.frame.origin.x, self.image.frame.origin.y, self.image.frame.size.width, touchPoint.y + deltaWidth);
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x ,self.tableView.frame.origin.y + deltaHeight, self.tableView.frame.size.width, self.tableView.frame.size.height - deltaHeight );
self.viewTitle.frame = CGRectMake(self.viewTitle.frame.origin.x ,self.viewTitle.frame.origin.y + deltaHeight, self.viewTitle.frame.size.width, self.viewTitle.frame.size.height);
}
}
但每次拖动图像后:self.image.frame.size.height = 100或300,我无法调整图像大小。他需要一直拖延! 谢谢!
编辑: 我不想在heightImage为100时调整大小。
我的原始图像高度为200.我的用户可以点击并调整图像大小,但不超过300且小于100.我只需要设置最小和最大高度。我希望你现在明白。
答案 0 :(得分:1)
您是否尝试过测试<=
和>=
?
if (self.image.frame.size.height >= 100 && self.image.frame.size.height <= 300) {
//...
}
答案 1 :(得分:0)
我解决了这个问题。
int aux=touchPoint.y + deltaWidth;
if (aux>300) {
aux=300;
}
else if(aux<100){
aux=100;
}
self.image.frame = CGRectMake(self.image.frame.origin.x, self.image.frame.origin.y, self.image.frame.size.width, aux);