You cannot contribute anything except cash to an IRA, and that only subject to having compensation (earned income such as salary, wages, self-employment income, commissions on sales, etc): the limit is $5500 (more for older people) or total compensation whichever is smaller. So, if you are eligible to contribute to an IRA and have unrealized capital gains on investments, you cannot transfer those investments into the IRA: you have to cash in the investments (and pay tax on those capital gains) and contribute cash to the IRA, Whether or not you buy the same investment inside the IRA is totally irrelevant.
When you take money out of an IRA, you are getting only cash. Now, some IRA custodians will give you appreciated stock or mutual fund shares out of the IRA to hold in your non-IRA brokerage account, but as far as the IRS is concerned, it is as though the IRA custodian sold the investment, gave you the proceeds of the sale, and you promptly bought the same investment outside the IRA, all without any party having to pay any brokerage fees etc. for the sale and repurchase of the investment. The value of the distribution is the closing price of the investment on the day of the distribution.