移動圖片

-(void)chooseRect{
    
    float newX=0,newY=0;
    CGRect newFrame;
    newX = sourceView.frame.origin.x + endPoint.x-beginPoint.x;
    newY = sourceView.frame.origin.y + endPoint.y-beginPoint.y;    
    
    if(newX + sourceView.frame.size.width <= showView.frame.origin.x + showView.frame.size.width)
    {
        newX = sourceView.frame.origin.x - showView.frame.origin.x - showView.frame.size.width
            + sourceView.frame.origin.x + sourceView.frame.size.width;
    }
    else if(showView.frame.origin.x <= newX)
    {
        newX = sourceView.frame.origin.x + ( showView.frame.origin.x -
                +sourceView.frame.origin.x);
    }
    else
    {
        newX = newX;
    }
    
    if(newY + sourceView.frame.size.height <= showView.frame.origin.y + showView.frame.size.height)
    {
        newY = sourceView.frame.origin.y + showView.frame.origin.y + showView.frame.size.height
        - sourceView.frame.origin.y - sourceView.frame.size.height;
    }
    else if(showView.frame.origin.y <= newY)
    {
        newY = sourceView.frame.origin.y +
        (showView.frame.origin.y - sourceView.frame.origin.y);
    }
    else
    {
        newY = newY;
    }
    //sourceView.frame.origin = CGPointMake(newX, newY);
    
    CGRect newRect = CGRectMake(newX,newY, sourceView.frame.size.width, sourceView.frame.size.height);
    sourceView.frame = newRect;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章